Expressionengine 将 jQuery 花括号解释为 EE 标签
我正在使用 EE2.2 以及 jQuery 和 jQuery 模板插件。在我的模板中,我分配了花括号,这是 jQuery 模板工作原理的一部分。问题是 EE 没有区分 JavaScript 大括号和同样包含在大括号中的 EE 标签。 EE 将大括号解释为 EE 标签,因此模板无法正常工作。由于这些大括号位于 script 标记内,因此我假设 EE 会将它们视为 javascript 和非 EE 标记相关。我如何告诉 EE 这些不是 EE 标签。有解决这个问题的方法吗?
<script id="template-download" type="text/x-jquery-tmpl">
<tr class="template-download{{if error}} ui-state-error{{/if}}">
{{if error}}
<td></td>
<td class="name">${name}</td>
<td class="size">${sizef}</td>
<td class="error" colspan="2">Error:
{{if error === 1}}File exceeds upload_max_filesize (php.ini directive)
{{else error === 2}}File exceeds MAX_FILE_SIZE (HTML form directive)
{{else}}${error}
{{/if}}
</td>
{{else}}
<td class="preview">
.....
</script>
I'm using EE2.2 along with jQuery and jQuery templating plugin. In my template i have allot of curly braces that is part of how jQuery Templating works. The problem is EE is not differentiating between JavaScript curly braces and EE tags which also comes in curly braces. EE is interpreting the curly braces as EE tags and for that reason the template not working. Since these curly braces are inside a script tag, i would assume EE would count them as javascript and non EE tag related. How can i tell EE that these are not EE tags. Is there a work around this.
<script id="template-download" type="text/x-jquery-tmpl">
<tr class="template-download{{if error}} ui-state-error{{/if}}">
{{if error}}
<td></td>
<td class="name">${name}</td>
<td class="size">${sizef}</td>
<td class="error" colspan="2">Error:
{{if error === 1}}File exceeds upload_max_filesize (php.ini directive)
{{else error === 2}}File exceeds MAX_FILE_SIZE (HTML form directive)
{{else}}${error}
{{/if}}
</td>
{{else}}
<td class="preview">
.....
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
ExpressionEngine 的隐藏
$config['protect_javascript']
实际上是做什么的?也许最好用一个例子来解释——请允许我来说明一下。给定以下代码示例,使用
$config['protect_javascript'] = 'y';
高级条件将被完全忽略:这将产生以下输出:
而当
$config[' protected_javascript'] = 'n';
上面的相同代码片段将允许评估高级条件并生成:如您所见,区别在于是否高级条件在 JavaScript 代码块中进行评估。
简单条件 和 模板标签 始终在
标签中进行评估,无论
$config['protect_javascript']
是什么环境— 只需确保将大括号{}
放在单独的行上即可!What does ExpressionEngine's hidden
$config['protect_javascript']
actually do? It's probably best explained by an example — allow me to illustrate.Given the following code sample, with
$config['protect_javascript'] = 'y';
advanced conditionals will completely be ignored:Which will produce the following output:
Whereas, when
$config['protect_javascript'] = 'n';
the same code snippet from above will allow advanced conditionals to be evaluated and will produce:As you can see, the difference is whether or not advanced conditionals are evaluated in JavaScript code blocks.
Simple conditionals and template tags are always evaluated in
<script>
tags, regardless of the$config['protect_javascript']
setting — just be sure to place your curly braces{}
on separate lines!这是一个常见问题,之前已得到解答。简而言之:
{}
放在单独的行上,或者$config['protect_javascript']
隐藏配置变量根据您的使用情况,第二个选项可能是最好的解决方案。
This is a common question that has been answered before. Simply put:
{}
on separate lines, or$config['protect_javascript']
Hidden Configuration VariableWith your usage, the second option is probably the best solution.
您还可以将模板类型设置为“静态”以便轻松修复。如果您的 JS 与其他 EE 代码位于模板中,您可以将其移动到“静态”模板并嵌入它。
You can also set your template type to "static" for an easy fix. If your JS is in a template with other EE code, you can move it to a "static" template and embed it.