use } into smarty string

为君一笑 提交于 2019-12-11 06:29:09

问题


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


回答1:


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




回答2:


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.


来源:https://stackoverflow.com/questions/5301308/use-into-smarty-string

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!