top

Scripting vs. PluginCall

CMSimple scripting was originally introduced in CMSimple to give the user comprehensive control over the behavior of CMSimple for each individual page. Plugin calls (PluginCalls) make this goal easier and clearer to achieve in CMSimple_XH.

CMSimple-Scripting

CMSimple scripting is actually an outdated technique. CMSimple_XH now offers better and easier to understand ways to influence the system. Nevertheless CMSimple-Scripting still works in many cases and could be useful in special cases. In the following the possibilities of CMSimple-Scripting are briefly explained.

 

CMSimple scripting is noted by default according to the following scheme:

#CMSimple ... #

Only one CMSimple script may be written on each page (except #CMSimple hide#). If more than one CMSimple script is needed, they must all be noted in one block, for example, like this:

#CMSimple $description='My description'; $keywords='My keywords';#

It doesn’t matter where the CMSimple scripts are placed on the page, but make sure to insert them in the HTML source view of the editor.

 

There are a myriad of possibilities for what you can affect with CMSimple scripting. These include:

  • whether a page is published
  • whether a page should be displayed in the menu
  • whether a different template should be used for a page
  • whether a page should be redirected
  • whether to display the date when the page was last edited
  • page title, keyword, description and hints for robots

In CMSimple_XH all these things can be controlled much easier by making the appropriate page settings in the PageData tabs (see description here). So CMSimple scripting is no longer needed for these things.

 

CMSimple scripting is not a separate scripting language. Users who are already familiar with PHP should not have to learn a new scripting language. By accessing the full CMSimple framework, there are few restrictions on what can be done with CMSimple scripting. However, this flexibility comes at a price. Sometimes it is hard to understand what a complex CMSimple script does, and it is even harder to know how to do something specific with CMSimple scripting.

 

Note that outputting code by calling echo or print does not work as expected. Instead, all output should be written to $output. This variable contains the contents of the page when the script is executed, so you should usually append your output to $output. Example:

#CMSimple $output.= function(parameter);#

Experienced PHP programmers, can take a look at the Developer Documentation, where variables and functions of CMSimple_XH are listed. Some of them might be useful for advanced use of CMSimple scripting.

Alternative: PluginCall

Having learned so much about CMSimple scripting, the recommendation now is to avoid it if possible. It’s difficult to read and write in the editors, and because of the use of $output, it’s not exactly intuitive. Instead, use the plugin call:

{{{funktionName(parameter);}}}

This will output the return value of funktionName(parameter) exactly where it is on the page. It is primarily intended to call plugins – but you can also call any other correct PHP function with it.

The brackets and the semicolon at the end are optional. So you could also write:

{{{funktionName parameter}}}

It is possible to add a comment to the function. So you can add a reminder for yourself or notes for other users. The comment is placed in front of the function, separated by a colon. Example:

{{{DO NOT MODIFY THIS LINE:plugin('...');}}}

If you need a function that doesn't exist yet, just define it in the userfuncs.php file. This file (description) will be included by CMSimple_XH, so that all functions defined there are usable on the page. This way the page content will not be overloaded by complex scripting and can not be damaged accidentally during page editing.

Example

If you want to display the result of any PHP expression, you can use PHP's trim() function and pass the expression as a parameter, for example:

{{{trim(83 * 17 + 42);}}}

PHP

PHP = Hypertext Preprocessor, originally Personal Home Page Tools

PHP is a scripting language commonly used to create dynamic websites.

Templates

Templates are design patterns for websites that behave like masks. They determine the place where elements appear and influence their appearance.