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

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
主站蜘蛛池模板: 巴中市| 乌审旗| 秦安县| 休宁县| 左贡县| 金秀| 金秀| 田东县| 钟祥市| 常宁市| 衢州市| 长兴县| 射阳县| 阜平县| 绍兴市| 辽阳市| 大城县| 东兰县| 林州市| 鄱阳县| 英吉沙县| 丰台区| 平塘县| 溧阳市| 韶山市| 彭阳县| 闽侯县| 会宁县| 舞阳县| 丹阳市| 田阳县| 合水县| 兴安盟| 建阳市| 昆明市| 静乐县| 汉中市| 泉州市| 紫金县| 华蓥市| 芒康县|