Call a Smarty tag from a UDT

  Previous article Next article  

Call a Smarty tag from a UDT

  Article optimized for CMSMS 2.x

  Author:
  Last tested in: CMSMS 2.1.3
  Last updated: 28-05-2016
  Comments: 5

For my pneumatic tube website I am using the Products module for CMS Made Simple as an image library. The module is great for this purpose, I can add images and can store additional information in custom fields. But for adding a single image to a page I needed a large moduletag with parameters. If at some point I want to change something here I need to change all tags in the pages...
I searched and found a methode to make this easier for me. The idea behind this is you create a simple User Defined Tag which contains the large module tag, with a single parameter you can call this UDT.

Note: You need to have a grasp of PHP knowledge to use this tutorial! If you don't have it, but still want to use this UDT then Google is your best friend. The feedback form below and the CMSMS forum isn't the place for these kind of questions!

  How to use

First you need to have a clear picture what you want to make, especially what kind of parameter do you want. In my case I needed an ID parameter...
Create a new User Defined Tag and use a short and easy to remember name, in example "ShowProduct". In my case the content of the UDT is:

ShowProduct
$id = isset($params['id']) ? $params['id'] : '';
$smarty_data = "{Products action='details' productid='".$id."' detailtemplate='foo'}";
$smarty->display('eval:'.$smarty_data);

In stead of using the long module tag:

{Products action='details' productid=123 detailtemplate='foo'}

I now can use the short version in my pages:

{ShowProduct id=123}

A very efficient way of working, but you don't do this for a few moduletag calls. In my case it is worth the trouble, because I use it a few hundred times :)


A2 Webhosting CMS Made Simple

Other examples

Fetch the content of a Smarty tag from a UDT

An example posted by Hendrik, read the checkbox "This page is searchable" in the options tab of the page, and use it in the HTML template to hide the page from search engines (or not).
Create the UDT:

metasearchable
echo '<meta name="robots" content="'.(( $smarty->fetch('eval:'."{page_attr key='searchable'}") == 1 ) ? 'index,follow' : 'noindex' ).'" />';

In the <head> area of your website, you can add the tag at the spot you want the robots - noindex line:

{metasearchable}

  Working example






A2 Webhosting CMS Made Simple

  Comments

  Click here to leave a comment






This is a captcha-picture. It is used to prevent mass-access by robots. (see: www.captcha.net)
  « Enter the CAPTCHA code (lower case)

Your IP address will be stored on submit. I reserve the right to change or delete your response without notice!
In case of abuse your IP address will be blocked!


Can I have your attention for a moment?

Did this tutorial help you solving a problem at your (clients) website and it saved you many hours of work? Great!!
Consider buying Rolf a cup of coffee in return! [ Click here ]


  5 Comments

CMS Made Simple 2.2.2 - Tutorials, tips and tricks - CMSMS 2.2.2

Call a Smarty tag from a UDT

  Article optimized for CMSMS 2.x

  Author:
  Last tested in: CMSMS 2.1.3
  Last updated: 28-05-2016
  Comments: 5

A2 Webhosting CMS Made Simple