gab*_*abe 20 grails templates sitemesh gsp
当我在gsp模板中使用标准的jsp注释块时
<%-- some server-side comment --%>
Run Code Online (Sandbox Code Playgroud)
,sitemesh引发'意外令牌'错误.我可以使用另一种评论语法吗?
MAl*_*lex 17
你错过了'%'的标志.把它写成:
<%-- some server-side comment --%>
Run Code Online (Sandbox Code Playgroud)
最初的问题是询问如何注释掉 GSP 文件中的任何内容。唯一对我有用的是
<%-- some code to comment out --%>,
其他答案将不起作用,特别是如果被注释的代码是 grails 标签。%{ 和 <% 不起作用。
之前的答案(以及问题本身)有些混乱,我希望一开始就向我解释。.gsp 上有几种类型的服务器端注释。因此,在 .gsp 文档中,服务器端注释如下:
<%@ page contentType="text/html; charset=UTF-8" %>
<html>
<head></head>
<body>
<!-- the basic HTML comment (not on server side) -->
<h1>Visible on client side</h1>
<%-- GSP common comment (server side only) --%>
%{-- GSP alternative approach (again, on server side only) --}%
<g:if test="${true}">
<h1>Invisible on client side, just in source code</h1>
</g:if>
<p>and the one asked for happens elsewhere,
whenever you write classic Groovy script</p>
<g:set var="myTitle"/>
<%
myVar = 'comment'
if(myVar.equals('comment')){
/*Needs the classic Java comment,
this happens whether you're writing a simple .gsp
or any _template.gsp*/
myTitle = "<h1>Visible on server side only</h1>".encodeAsRaw()
}
%>
${myTitle}
<p>.gsp template does not modify comment behaviour</p>
<g:render template="/templates/myTemplate" model="[:]"/>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
文件:_myTemplate.gsp
<h2>Template</h2>
<!-- visible -->
<% invisible %>
%{-- invisible --}%
<% /*invisible*/ %>
Run Code Online (Sandbox Code Playgroud)
(Grails 2.5.5)
常规的 java 注释块就可以工作
<% /* some server side comment */ %>
Run Code Online (Sandbox Code Playgroud)