{literal}{/literal}

  • Overview

    The {literal} template block is used to tell smarty that all the code in this section should not be processed.

    It is useful if you need to paste javascript into templates. Use the {literal} tag so that smarty does not try to process the external code. Both smarty and javascript have a meaning for the { character. Their meanings are different and not compatible.

    Because Jamroom uses Smarty template engine for the templates there can sometimes be conflicts with javascript that has been copied and pasted.

    In those instances, using the {literal}{/literal} tags to wrap the javascript can save your butt.
  • This piece of code WILL break your site

    This piece of code WILL break your site
    screenshot of standard google analytics code
  • The above piece of code pasted directly into a jamroom template WILL break your site.

    Its not because the code is wrong, its just that there is a conflict between what each language operating thinks the code means.

    In smarty things that start with a { and are immediately followed by another character, smarty thinks is for it.

    So smarty will try to process all of these:
    {$some_variable}
    {jrCore_list}

    Because there is no space between the { and the following character.

    If however you put
    { $some_variable}
    { jrCore_list}

    Then those items would come out exactly as they are seen.
  • Javascript uses { too

    Javascript uses the { character too.

    So while the above google analytics code would work fine if the page was a regular old HTML page, it breaks for smarty templates.

    There are a couple of ways to get around the breakage.
    * Locate every location in that code that has a {x and put a space between it, { x.
    * OR wrap the whole block in {literal}{/literal} tags

    By far the easiest way for a large block of code is to put a literal at the top and at the bottom.

    That means: "Treat everything from here exactly as its written, so don't process any {$something} or {jrCore_list} items found in this section."

    and as long as there are no smarty variables that need to be processed in that section, then you javascript will fire as expected.
  • The Fix

    Below is the same code as above, but this time there is a {literal} tag before the start of the javascript and and a closing one {/literal} after the end of the javascript, so the javascript will work as expected.
  • screenshot of google analytics code wrapped in a {literal} block

Share This

Tags