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

  • concrete5 Cookbook
  • David Strack
  • 201字
  • 2021-08-13 16:15:57

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
主站蜘蛛池模板: 江山市| 左云县| 建湖县| 广安市| 淅川县| 莒南县| 顺昌县| 中江县| 登封市| 青铜峡市| 平顺县| 德保县| 防城港市| 绥德县| 宜兰县| 惠来县| 文登市| 岳池县| 革吉县| 开封县| 上栗县| 石家庄市| 霍山县| 垦利县| 颍上县| 巴里| 桃源县| 西畴县| 泸定县| 阿拉善盟| 马龙县| 九龙县| 上饶县| 吉木萨尔县| 乌审旗| 松溪县| 芒康县| 内乡县| 黔西| 乳山市| 沿河|