- CMS Made Simple Development Cookbook
- Samuel Goldstein
- 571字
- 2021-04-09 21:13:17
Will a Tag Solve My Problem?
As in the previous recipe, you know that we have three different possibilities for extending CMS Made Simple and solving a problem: User-Defined Tag, Tags, and Modules. Deciding which of these is the best approach, however, requires additional knowledge about the strengths and weaknesses of each technique.
This recipe will help you examine your problem and consider whether creating a Tag is the most appropriate solution.
How to do it...
The criteria for deciding to use a Tag to extend CMS Made Simple are quite similar to the criteria for a User-Defined Tag.
To figure this out, consult the following list, and determine if each item applies to the problem you are trying to solve. Feel free to write down a list of your answers (yes/no).
- Can your problem be solved with Smarty logic in your page template?
- Are you trying to solve a problem that requires multiple actions? An example of multiple actions would be both displaying a form and processing its results.
- Will you need to support localization and internationalization to solve your problem? For example, if your code will be displaying messages, will the messages need to be translated into multiple languages?
- Will your solution require an Administration panel?
- Do you need to create new database tables or set up new preferences to solve your problem?
If you answered "no" to all of the above questions, either a Tag or a User-Defined Tag would be a viable approach. To decide whether a Tag would be better than a UDT, consider the following questions:
- Will you want to share this solution with other people so they can install it into their own CMS Made Simple sites, or will you want to reuse this code yourself on other sites?
- Do you want your code to display help text in the Admin area, so site administrators understand what parameters are available and what the code does?
- Will your solution serve as a Smarty modifier? A Smarty modifier is a function that reformats a variable for display, for example,
{$variable|uppercase}
where the modifier("uppercase")
serves to transform the variable ("$variable").
If you answer "yes" to any of these three questions, you should write a Tag instead of a User-Defined Tag.
How it works...
A Tag is a way to connect a Smarty tag to some PHP code. The PHP code can do anything. Like in the case of User-Defined Tags, there are very few things that cannot be done in CMS Made Simple using Tags.
Because Tags are so versatile, the best way to determine if they are the ideal approach is by disqualification. We ask questions about the few things for which Tags are not ideal, to see if any of those things match our requirements. If none of them match, then the problem could be solved by either a Tag or a User-Defined Tag. To make the decision between those two approaches, we consider a few other criteria that will steer us in the right direction.
Let's consider the disqualifying questions again and examine why they would encourage us to use a different approach. The first five questions are the same as they were for User-Defined Tags.

Now, let's consider the three things that differentiate a Tag from a User-Defined Tag:

See also
- Will a User-Defined Tag Solve My Problem recipe?
- Will a Module Solve My Problem recipe?
- Create a "Hello World" Tag recipe
- Photoshop CC 2018實用教程
- CAXA CAD電子圖板2020工程制圖
- Hadoop核心技術
- Adobe創意大學Illustrator產品專家認證標準教材(CS6修訂版)
- Maya 2019三維動畫基礎案例教程
- ASP.NET jQuery Cookbook
- 會聲會影視頻編輯實戰秘技250招
- Oracle Fusion Middleware Patterns
- Oracle Warehouse Builder 11g R2: Getting Started 2011
- 詳解AutoCAD 2022室內設計(第6版)
- Python Testing Cookbook
- 中文版3ds Max 2014-VRay效果圖制作完全自學教程
- MSC Fatigue疲勞分析標準教程
- 短視頻拍攝、剪輯、調色與特效制作:剪映專業版+Premiere Pro 2024(全彩微課版)
- Learn OpenOffice.org Spreadsheet Macro Programming: OOoBasic and Calc automation