- CMS Made Simple Development Cookbook
- Samuel Goldstein
- 573字
- 2021-04-09 21:13:18
Create a "Hello World" User-Defined Tag
If you have decided to create a User-Defined Tag to solve a problem, you might want to know what a UDT looks like.
This recipe shows you how to make a simple User-Defined Tag.
Getting ready
Like most of the recipes in this book, you will need to have CMS Made Simple installed and working. You will need login access to the site's Administration area as a member of the "Admin" group (or as a member of a group with "Modify User-defined Tags" and "Add Pages" permission settings).
How to do it...
- Log in to the Administration panel of your CMS.
- On the top menu, select "Extensions" and click on "User-Defined Tags".
- Click on the "Add User Defined Tag" button.
- Enter the name "helloworld" in the"Name" field for your new User-Defined Tag.
- Enter the following code snippet into the "Code" field, and click on"Submit".
echo "Hello World, Welcome to CMS Made Simple version ".CMS_VERSION;
- On the top level menu, select "Content" and click on "Pages".
- Click on the "Add New Content" button.
- Fill in the name of the new page as "Hello World".
- Enter "Hello World" as the menu text.
- For the page content, put in your new tag
{helloworld}
, and then hit "Submit". - View your site from the user side. Click on the new "Hello World" page.
- Admire the output from your User-Defined Tag!
How it works...
A User-Defined Tag is a way of attaching arbitrary PHP code to a Smarty tag. When the CMS Made Simple templates get parsed, Smarty will call the User-Defined Tag and execute the code. Any output from the code will be substituted into the template at the point of the tag.
Our basic example creates a Smarty tag which is called "helloworld." The code for the tag simply outputs a string of text, in this case, the welcome message. To add a bit of interest, we also have it output some useful information: the version of CMS Made Simple that you're running. That value is available in CMS Made Simple via a PHP define, and it can be used in any code run by the CMS.
There's more...
Keep in mind that CMS Made Simple page content is also sent to Smarty for processing — even though we consider it "Content", Smarty regards it as a template. This means that you can place your User-Defined Tag in your underlying page template or in your page content, and it will work just the same either way.
We've seen that any output from a User-Defined Tag gets substituted for that tag in the final rendering of the page. It may not be obvious at first, but UDTs aren't required to produce output at all! A User-Defined Tag may do invisible things behind the scenes: set a flag in the PHP session object, update a counter, and even generate an e-mail. If a UDT does not create any visible output, its Smarty tag will simply be removed from the finally rendered page.
Caching
CMS Made Simple has mechanisms built-in for caching pages in order to improve performance. Under normal circumstances, a User-Defined Tag is not cached — if the UDT creates output, that output is not cached. Similarly, if a UDT does not create any output, it will be called even if the page itself is cached.
See also
- Will a User-Defined Tag solve my problem recipe?
- Create a "Hello World" tag recipe
- Irrlicht 1.7 Realtime 3D Engine Beginner's Guide
- ANSYS 14熱力學·電磁學·耦合場分析自學手冊
- IBM Lotus Notes 8.5 User Guide
- 中文版CorelDRAW基礎培訓教程
- Dreamweaver CC實例教程(第5版·微課版)
- DSP開發(fā)寶典
- 數(shù)碼攝影后期處理秘笈:Photoshop CC專業(yè)調(diào)色(第2版)
- 工業(yè)軟件研發(fā)、測試與質(zhì)量管理論叢
- 3ds Max/MaxScript印象 腳本動畫制作基礎與應用
- PHP 5 Social Networking
- Vue.js快速入門
- 中文版3ds Max/VRay效果圖制作完全自學教程(實例培訓教材版)
- RAW 數(shù)碼底片演義
- 邊做邊學:Illustrator CS6平面設計案例教程(微課版)
- Excel 2010 Financials Cookbook