Macros

Macros are basically functions (and a good way to reuse code). You can input numerous values into the function do this by not including a comma.

The important part of the macro is the first line: #macro is just the command to call a macro, then inside the brackets you must place the name of the macro, in this case the function macro is called contentType. After the macro name you include the values.

The example below picks up the type and then displays an image based on the contentType or $type.

A macro itself in full looks like the following:

  1. #macro (contentType $type)  
  2.     #if($type=="blog")  
  3.         <img src="/application/assets/images/blog-badge-small.png" alt="blog">  
  4.     #elseif($type=="photo")  
  5.         <img src="/application/assets/images/photo-badge-small.png" alt="photo">  
  6.     #elseif($type=="video")  
  7.         <img src="/application/assets/images/video-badge-small.png" alt="video">  
  8.     #elseif($type=="events")  
  9.         <img src="/application/assets/images/event-badge-small.png" alt="event">  
  10.     #end  
  11. #end  

To call a macro use the following line. The name of the macro is contentType. Place a value or two between the brackets:

  1. #contentType("$!{article.contentType.selectValue}")  
comments powered by Disqus