- CMS Made Simple Development Cookbook
- Samuel Goldstein
- 594字
- 2021-04-09 21:13:16
Will a User-Defined Tag solve my problem?
You have reached the point where you know you need to extend CMS Made Simple to solve some particular problem, but you may not yet know what approach to take. Your options are to create a Tag, a User-Defined Tag (UDT), or a Module, but which will be best to solve your specific problem?
This recipe will help you examine your problem and consider whether creating a UDT is the most appropriate solution.
How to do it...
First, we determine if the problem you want to solve is one that will require you to write some custom code. This is the easy part. You've already considered whether or not an existing solution will suffice and have decided that it will not. So the next step is to figure out whether or not a User-Defined Tag is the correct approach to solving the problem.
Go through the following list, and for each item, determine if it 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 or standard CMS authoring practices like using Global Content Blocks 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?
- Will you want to share this solution with other people so that they can install it into their own CMS Made Simple sites?
- Do you need to create new database tables or set up new preferences to solve your problem?
- 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 modifier in Smarty is a function that does something to convert a variable for display)? An example of a Smarty modifier would be
{$variable|uppercase}
where the modifier ("uppercase") serves to transform the variable ("$variable").
If you answered "no" to all of the above questions, a User-Defined Tag is a good candidate!
How it works...
A User-Defined Tag is a way to connect a tag, that will be recognized by Smarty, to an arbitrary bit of PHP code. That PHP code can do anything. While there are very few things that cannot be done in CMS Made Simple using UDTs, it doesn't necessarily mean that a UDT is the best approach for everything. Because User-Defined 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 UDTs are less optimal, to see if any of those things match our requirements. If none of them match, then a User-Defined Tag is probably the best approach.
If we do find that our requirements include functionality for which UDTs are not ideally suited, we should consider using a Tag or a module instead. We will explore these options in greater detail elsewhere in this chapter.
For now, let's look at those qualifying questions again and examine why they would encourage us to use a different approach.

See also
- Will a Tag Solve my Problem recipe?
- Will a Module Solve my Problem recipe?
- Create a "Hello World" User-Defined Tag recipe.
- Photoshop CC中文版基礎(chǔ)與實(shí)例教程(第7版)
- SPSS進(jìn)階分析與實(shí)務(wù)
- Excel 2013電子表格處理
- Photoshop日系少女寫真后期解密
- BlackBerry Enterprise Server 5 Implementation Guide
- 新印象:CINEMA 4D電商設(shè)計(jì)基礎(chǔ)與實(shí)戰(zhàn)(全視頻微課版)
- Backbone.js Cookbook
- CakePHP Application Development
- Adobe創(chuàng)意大學(xué)Premiere Pro產(chǎn)品專家認(rèn)證標(biāo)準(zhǔn)教材(CS6修訂版)
- Origin 2022科學(xué)繪圖與數(shù)據(jù)分析
- 攝影師的后期必修課(RAW格式篇)
- 寫給大家看的PPT設(shè)計(jì)書(第2版)
- Away3D 3.6 Cookbook
- 老郵差Photoshop數(shù)碼照片處理技法通道篇(修訂版)
- 讓你的PPT更精美:美化PPT必備100招