- 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:
- Open
/config/site_post.php
in your preferred editor. This is a good place to run some arbitrary code. - Load the
Page
object.$page = Page::getByPath('/about');
- Get the
meta_title
attribute.$title = $page->getAttribute('meta_title');
- 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
推薦閱讀
- Kali Linux Web Penetration Testing Cookbook
- Cocos2d-x游戲開發:手把手教你Lua語言的編程方法
- React Native Cookbook
- C#程序設計教程
- Python時間序列預測
- C/C++程序員面試指南
- Java高并發核心編程(卷1):NIO、Netty、Redis、ZooKeeper
- Microsoft Dynamics AX 2012 R3 Financial Management
- Scratch3.0趣味編程動手玩:比賽訓練營
- RESTful Web Clients:基于超媒體的可復用客戶端
- 從程序員角度學習數據庫技術(藍橋杯軟件大賽培訓教材-Java方向)
- Java 9 with JShell
- Hands-On Dependency Injection in Go
- Java Web開發教程:基于Struts2+Hibernate+Spring
- Mastering ASP.NET Web API