returnvoid
returnvoid

Reputation: 434

use } into smarty string

Im trying to use the key sign '}' inside a string of smarty template but it generate an error. The problem only ocurrs with '}' and not with '{´. I need print:

var naciones = [{label:'Country', value:'1'}, {label:'Country', value:'2'}];

solution:

var naciones = [{/literal}{foreach from=$paises item=pa}{literal}{label:"{/literal}{$pa->getNacionalidad()}{literal}", value:"{/literal}{$pa->getId()}{literal}"},{/literal}{/foreach}{literal}];

example:

{literal}
<script type="text/javascript">
var naciones = [{/literal}
{foreach from=$paises item=pa}
{'{label:"'|cat:$pa->getNacionalidad()|cat:'", value:"'|cat:$pa->getId()|cat:'"'}{cat:'"}, '}{/foreach}{literal}];
$('#nacionalidad-ac').autocomplete({
  source:naciones,
  change: function(event, ui){
    $('#nacionalidad').val(ui.item.value);
  }
});
</script>
{/literal}

thanks

Upvotes: 1

Views: 1984

Answers (2)

Michael Berkowski
Michael Berkowski

Reputation: 270727

You need the {literal} {/literal} tag to properly escape the curly braces in a Smarty template. Also necessary for inline Javascript which has braces.

Upvotes: 2

Nanne
Nanne

Reputation: 64419

You can use {literal} to stop parsing. So a smarty template with a '{' would look like

This is just a text with a {$smartyString}
There is also an {literal} } {/literal} sign in here that could give you some trouble.

Upvotes: 2

Related Questions