William Jiang

JavaScript,PHP,Node,Perl,LAMP Web Developer – http://williamjxj.com; https://github.com/williamjxj?tab=repositories

smarty: {literal}{/literal} replaced by whitespace

smarty: {literal}{/literal} replaced by whitespace(‘ ‘)

In HTML templates library smarty, the {literal}{/literal} pairs are used to seperated javascript/css from Smarty templates codes.

{literal} tags allow a block of data to be taken literally. This is typically used around Javascript or stylesheet blocks where {curly braces} would interfere with the template delimiter syntax. Anything within {literal}{/literal} tags is not interpreted, but displayed as-is. If you need template tags embedded in a {literal} block, consider using {ldelim}{rdelim} to escape the individual delimiters instead.

Note:
{literal}{/literal} tags are normally not necessary, as Smarty ignores delimiters that are surrounded by whitespace.
So, Be sure your javascript and CSS curly braces are surrounded by whitespace. This is new behavior to Smarty 3. Examples:

//1. previous:
if (form.validationEngine({literal}{returnIsValid:true}{/literal})) 
  {...}

{literal}css = 
  {'width':200px;'height':100px;background-color: red}{/literal}

//2. now:
if (form.validationEngine({  returnIsValid:true   })) {...}

css = {   'width': 200px; 'height': 100px; background-color: red   }

This make the codes easier to read and maintain.

Advertisements

One response to “smarty: {literal}{/literal} replaced by whitespace

  1. powercashadvance.com 10/26/2011 at 4:51 pm

    It was something of great contentment locating your site recently. I arrived here right now hoping to get something new. And I was not disappointed. Your ideas about new techniques on this topic were enlightening and a good help to my family. Thank you for making time to write out these things and for sharing your notions.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: