Book Image

CMS Made Simple Development Cookbook

Book Image

CMS Made Simple Development Cookbook

Overview of this book

CMS Made Simple has great capabilities “out of the box,” but one of its great strengths is the ease of extending those capabilities. You can add a surprising amount of functionality just by customizing the core modules, but once you learn to write your own tags and modules, your ability to add features is virtually limitless.CMS Made Simple Development Cookbook will show you how to use custom PHP code to extend the power and features of CMS Made Simple, and make it do exactly what you want. This easy to use guide contains clear recipes that introduce the key concepts behind each approach to extending the CMS, while also providing examples of solutions to real-world problems.You will learn the differences between the various kinds of tags and modules in the CMS Made Simple environment, and to which purposes each is best fit. Each technology is then explored in detail with a series of practical recipes and examples.You will not only learn the basics of creating tags and modules, but you will explore the underlying APIs that you will use to solve real-world website problems. You will become proficient with the database and form APIs, so that the code you write is portable and maintainable. You'll learn to localize your code and use templates to add its flexibility. You'll master the safe handling of parameters and the creation of secure code. You’ll be familiar with the CMS Made Simple Developer's Forge, and how you can use it in conjunction with revision control as a community-focused code management system, complete with web-based bug tracking and feature requests. You will learn to code complex interactions between modules, both directly and via the creation and handling of events. You will gain exposure to an array of advanced tips and tricks, along with commentary from the distilled experience of someone who has written dozens of modules. The CMS Made Simple Developer's Cookbook offers an amazing wealth of knowledge in approachable, bite-sized recipes. Whether you're new to the CMS or an old hand, you're sure to find valuable tips and information that will have you creating a richer CMS.
Table of Contents (16 chapters)
CMS Made Simple Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface

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).

  1. 1. Can your problem be solved with Smarty logic in your page template?

  2. 2. 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.

  3. 3. 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?

  4. 4. Will your solution require an Administration panel?

  5. 5. 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:

  1. 1. 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?

  2. 2. 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?

  3. 3. 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.

Disqualifying Question

If you answered "Yes"

Can the problem be solved simply using Smarty?

If this is the case, we don't need to extend CMS Made Simple at all! For some great examples, please see Chapter 2, Programming with Smarty and Core Modules.

Does your problem require multiple actions?

It is, in fact, possible to handle multiple actions using a Tag, but the CMS Made Simple Module API has extensive support to simplify multiple actions, as well as conventions that will help keep the code separated nicely into maintainable chunks. Thus a Module would be a much better choice.

Do you need localization or internationalization?

These features could theoretically be implemented using a Tag, but there is no built-in support for either. The Module API, on the other hand, has facilities specifically to simplify those tasks.

Will you need an Administration Panel?

There is no easy way to implement an Administration panel in a Tag, while the Module API has numerous methods specifically for this purpose.

Do you need to create database tables or preferences?

You could write logic into your Tag to check on the existence and conditionally create database tables or preferences, but it would be easier to use the Module API which has specific support and standards for doing those operations.

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

Tag Qualifying Question

If you answered "Yes"

Will you be sharing this solution with other people?

A Tag is stored as a file on the server, which makes it easier to share with other CMS Made Simple users, since they can simply place the file in their own installation. A User-Defined Tag, on the other hand, is stored in the database, that adds extra steps if you want to share it.

Do you want your code to display help text in the Admin area?

The structure of a Tag has a special method for presenting information to the site administrator, while a User-Defined Tag has no such mechanism.

Will your solution serve as a Smarty modifier?

There are several kinds of Tags, including Smarty modifier tags. There is only one kind of User-Defined Tag, and it will not work as a Smarty modifier.

See also

  • Will a User-Defined Tag Solve My Problem recipe?

  • Will a Module Solve My Problem recipe?

  • Create a "Hello World" Tag recipe