简体   繁体   English

百里香-脚本和th:block

[英]thymeleaf - script and th:block

) Is there any way to use "th:block" tag inside "script" tag? )是否可以在“脚本”标签内使用“ th:block”标签? something like that: 像这样的东西:

<script type="text/javascript">
    <th:block>
        var test = 1;
    </th:block>
</script>

You should use the attribute th:inline="javascript" , then you can use a th:block but not in a tag, you must use a syntax like next: 您应该使用属性th:inline="javascript" ,然后可以使用th:block但不能在标记中使用,必须使用类似于next的语法:

<script th:inline="javascript">
    [#th:block th:each="item : ${items}"]
      - [#th:block th:utext="${item}" /]
    [/th:block]
</script>

We had the requirements to insert an external javascript (with thymleaf variables inside) and wrap it in cdata, it's based on @Pau's solution: 我们需要插入一个外部javascript(内部带有thymleaf变量)并将其包装在cdata中,它基于@Pau的解决方案:

<script th:inline="javascript">
  /*<![CDATA[*/
  /*[+ [# th:insert="~{path/to/file.js}" /] +]*/
  /*]]>*/
</script>

In these five lines we packed: 在这五行中,我们打包了:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM