官术网_书友最值得收藏!

Getting a page attribute

In addition to being able to set page attributes, developers can also retrieve attributes just as easily. In this exercise, we will get the Meta Title attribute for the About page.

Getting ready

We are assuming the presence of a page with the path of /about in this recipe. If that page does not exist, you can create it, or adapt the code in this recipe to fit your circumstances.

How to do it...

The steps for getting a page attribute are as follows:

  1. Open /config/site_post.php in your preferred editor. This is a good place to run some arbitrary code.
  2. Load the Page object.
    $page = Page::getByPath('/about');
  3. Get the meta_title attribute.
    $title = $page->getAttribute('meta_title');
  4. Dump the variable using the custom debugging function that we created in the chapter's introduction.
    my_debug($title);

How it works...

concrete5 uses the attribute handle string to find the appropriate record in the database and return its value. concrete5 stores attributes in the EAV format (entity, attribute, value), and this makes it difficult to read these values directly with SQL queries. The concrete5 API simplifies this for developers.

See also

  • The Getting a page by its path recipe
  • The Setting a page attribute recipe
主站蜘蛛池模板: 奈曼旗| 东丰县| 合江县| 永康市| 永州市| 平江县| 双柏县| 白银市| 罗甸县| 新乡县| 七台河市| 乐平市| 泰顺县| 农安县| 洛隆县| 营口市| 石阡县| 安泽县| 揭阳市| 阜平县| 德令哈市| 潮安县| 阆中市| 大同县| 武宣县| 乌什县| 鹤壁市| 闵行区| 当阳市| 乐山市| 久治县| 财经| 茶陵县| 云南省| 射洪县| 威海市| 永城市| 北流市| 腾冲县| 灌阳县| 罗田县|