我正在尝试使用 javascript 条件并将其与 smarty 代码混合...这可能吗?
例如:
<script>
if (myjsVar == '2') {
{some smarty here}
}
</script>
这就是我正在尝试做的事情:
{literal}
<script type="text/javascript">
myjsVar = '2';
if (myjsVar == '2') {
{include file='inc.html'}
}
</script>
{/literal}
此时此代码不包含任何内容...语法?
最佳答案
您可以使用literal允许按字面意思获取数据 block 。例如 Javascript 或 CSS
{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.
{literal}
<script type="text/javascript">
if (myjsVar == '2') {
{include file='inc.html'}
}
</script>
{/literal}
您还可以使用{ldelim} and {rdelim}用于转义 smartys 模板分隔符
<script type="text/javascript">
if (myjsVar == '2') {ldelim}
{include file='inc.html'}
{rdelim}
</script>
关于javascript - Smarty 内部 javascript 条件...可能吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35150439/