MENU

Call a Smarty tag from a UDT

  Previous article Next article  

For my pneumatic tube website I *used* the Products module for CMS Made Simple as an image library. The module was 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 module tag 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 method 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);

Instead 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 module tag calls. In my case it is worth the trouble, because I use it a few hundred times :)


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}

Buy Me A Coffee


  Comment Form

ReviewManager

Click here to open the form

ReviewManager

  5 Comments

Buy Me A Coffee

CMS Made Simple - Tutorials, Tips and Tricks - CMSMS

Call a Smarty tag from a UDT

  Article optimized for CMSMS 2.x

  Author:
  Last tested in: CMSMS 2.1.3
  Last updated: 10-06-2019
  Comments: 5
  http://cms.ms/0Ism


Buy Me A Coffee




Advertisement


Ads help me to help you! Thanks!

Ads help me to help you! Buy products from these advertisers!