Fork me on GitHub
 

What are Custom Tags ?


Custom Tags are tags that you can define and use anywhere on your ImpressCMS site. You could see them as extended BBCodes, but multilingual, with group permissions, supporting PHP, and usable in all the ImpressCMS text areas of the type 'AutoFormat', as well as in all templates ! 


Note : you can define a type of 'PHP' for your custom tag, but that doesn't mean your tag will work in a textarea of the type 'PHP'.


Scroll down this page for an example of Custom Tag usage.


Custom Tag usage example


Let's create 2 custom tags with these information: The first one:



  • Name : hello

  • Description : Custom tag to be used to greet a Webmaster user

  • Content : Hello, you are a Webmaster!

  • Language: All

  • Type: XCodes

  • View permission: Webmasters


The second one:



  • Name : hello

  • Description : Custom tag to be used to greet a Registered user

  • Content : Hello, you are a Registered user!

  • Language: All

  • Type: XCodes

  • View permission: Registered Users


The Third example:



  • Name : user_info

  • Description : Simple example of how to show some user informations in blocks or in the theme using a php custom tag.

  • Language: All

  • Type: PHP

  • View permission: All groups

  • Content : Add the code bellow


Help - Custom Tag


Create a block


Then, create a block, visible on home page by every group. Enter this, as the content of the new block:



Let's use a Custom tag below...


What will the user see ?


When a user will be looking at your home page, if he is a webmaster, the custom tag will be replaced by:



Let's use a Custom tag below...
Hello, you are a Webmaster!

If he is a Registered Users only, then the custom tag will be replaced by:



Let's use a Custom tag below...
Hello, you are a Registered user!

And finally, if the user is not loged in (Anonymous) then the custom tag will just be empty, and the user will only see:



Let's use a Custom tag below...

Can I use this in a template ?


Of course ! In any template of ImpressCMS, simply use this:



<{$icmsCustomtags.hello}>

Multilingual Custom Tags


Everytime you create a custom tag, you can select for which language this custom tag will be used. You can also select All if you want this custom tag to be used by all language.


Can I use PHP in the content of a custom tag ?


Yes you can! Simply select PHP as the Type of the custom tag, and, when rendered (providing the user is in one of the group selected in this custom tag, and that the user's selected language is the one linked to this custom tag or the custom tag is to be displayed for All languages), then the PHP code will be executed.


Can I use custom tags from PHP?


Yes you can! You will need the following code in your PHP page:



$icms_customtag_handler = icms_getModuleHandler("customtag", "system");
$customtags = $icms_customtag_handler->getCustomtagsByName();
if (isset($customtags["tag"])) echo $customtags["tag"]->render();

In summary ?


So, in summary, you can create all the custom tags you need, for any language you want, for any group you want.


When displayed, ImpressCMS will look for the custom tag that matches the user's language and its group permissions! Enjoy !

Last modified on 2012/10/25 by Anonymous
Comments
The comments are owned by the poster. We aren't responsible for their content.