use } into smarty string
Im trying to use the 开发者_StackOverflow社区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
You need the {literal} {/literal}
tag to properly escape the curly braces in a Smarty template. Also necessary for inline Javascript which has braces.
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.
精彩评论