Template Blocks

  • Overview

    Template Blocks are sections of code that work in templates that show a section depending on whether certain conditions are true. You can use them to show different sections to different people, ie "Only show this section if the user is logged in"

    A template block is similar to template functions in that they are both smarty code that goes into your template to achieve a purpose.
    But while a template function is a single item, template blocks wrap a section. They have a starting point and an end point.
  • Example

    An example of a template block is:
    {if jrUser_is_logged_in()} 
        // Put here the code to be run if the user is logged in
    
    {/if}
  • The block starts with an {if} statement followed by a condition. In this case the condition is a function that returns TRUE or FALSE for the question "Is the user logged in?"

    If the answer is TRUE then the section inside that block up until the closing of the block IS displayed.

    The block is closed with the closing if tag: {/if}
  • The Jamroom system uses Smarty 3 as its templating engine, all the info in the smarty docs will work in Jamroom Templates.
  • {if}{/if}

    The smarty docs for the if structure can be found here:
    http://www.smarty.net/docs/en/language.function.if
  • To find out all the variables you can run {if} statements against checkout the {debug} docs.

  • {foreach}{/foreach}

    {foreach} is another structure that takes an array of items and loops over them for each item in the array.

    You will often see a {foreach} loop in the results of a {jrCore_list} function.

Tags