Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "M2T-JET-FAQ/How to I escape JET special characters?"

(Tag lead-in characters: < and </)
 
Line 1: Line 1:
 
JET recognizes a number of characters is lead-ins to tags, comments, directives and embedded XPath expressions. If you need to include these characters in your template output, you need to escape them. Different techniques are required for different types of characters:
 
JET recognizes a number of characters is lead-ins to tags, comments, directives and embedded XPath expressions. If you need to include these characters in your template output, you need to escape them. Different techniques are required for different types of characters:
  
== Tag lead-in characters: < and </ ==
+
== Tag lead-in characters: &lt; and &lt;/ ==
  
To escape a < characters, place a backslash (\) in front of it. Example:
+
Your choices are the following alternatives:  
  
JET template text:
+
If you are working with JET 1.0 or later, you can escape the leading &lt; character with the compact XPath expression ${'&lt;'}&nbsp;:  
<pre>\<some text></pre>
+
<pre>
 +
${'&lt;'}c:iterate&gt;...${'&lt;'}/c:iterate&gt;
 +
</pre>  
  
Template output:
+
See [[M2T-JET/Whats New in 1.0 (Galileo)#Compact alternative to c:get tag|Compact alternative to c:get tag]], for more details.
<pre><some text></pre>
+
Alternatively, you can use the taglib directive to change the namespace of your tags.
 +
 
 +
You can change the namespace of the tags you emit:
 +
<pre>&lt;%-- Your template uses c:, but emits cc: for control tags --%&gt;
 +
&lt;%-- emit tag so that the output tags are bound to cc. This needs to be escaped --%&gt;
 +
&lt;\%@taglib prefix="cc" id="org.eclipse.jet.controlTags"&nbsp;%&gt;
 +
...
 +
&lt;c:if test="someCondition"&gt;
 +
  &lt;cc:iterate select="..."&gt;...&lt;/cc:iterate&gt;
 +
&lt;/c:if&gt;
 +
</pre>  
 +
Or, you can change the namespace of your template's tags:
 +
<pre>&lt;%-- Your template uses cc:, but emits c: for control tags --%&gt;
 +
&lt;%-- Indicate that this templates uses cc prefix for control tags --%&gt;
 +
&lt;%@taglib prefix="cc" id="org.eclipse.jet.controlTags"&nbsp;%&gt;
 +
...
 +
&lt;cc:if test="someCondition"&gt;
 +
  &lt;c:iterate select="..."&gt;...&lt;/c:iterate&gt;
 +
&lt;/cc:if&gt;
 +
</pre>  
 +
JET has used the latter technique since inception to generate new JET projects.
  
 
== Comment lead-in and closing characters: <%-- and --%> ==
 
== Comment lead-in and closing characters: <%-- and --%> ==

Latest revision as of 08:51, 31 July 2013

JET recognizes a number of characters is lead-ins to tags, comments, directives and embedded XPath expressions. If you need to include these characters in your template output, you need to escape them. Different techniques are required for different types of characters:

Tag lead-in characters: < and </

Your choices are the following alternatives:

If you are working with JET 1.0 or later, you can escape the leading < character with the compact XPath expression ${'<'} :

${'<'}c:iterate>...${'<'}/c:iterate>

See Compact alternative to c:get tag, for more details. Alternatively, you can use the taglib directive to change the namespace of your tags.

You can change the namespace of the tags you emit:

<%-- Your template uses c:, but emits cc: for control tags --%>
<%-- emit tag so that the output tags are bound to cc. This needs to be escaped --%>
<\%@taglib prefix="cc" id="org.eclipse.jet.controlTags" %>
...
<c:if test="someCondition">
   <cc:iterate select="...">...</cc:iterate>
</c:if>

Or, you can change the namespace of your template's tags:

<%-- Your template uses cc:, but emits c: for control tags --%>
<%-- Indicate that this templates uses cc prefix for control tags --%>
<%@taglib prefix="cc" id="org.eclipse.jet.controlTags" %>
...
<cc:if test="someCondition">
   <c:iterate select="...">...</c:iterate>
</cc:if>

JET has used the latter technique since inception to generate new JET projects.

Comment lead-in and closing characters: <%-- and --%>

JET comment lead-in and closing characters can be escaped by placing a backslash (\) before the % sign on the lead-in and the > on the closing:

JET template text:

<\%-- this is not a JET comment --%\>

Template output:

<%-- this is not a JET comment --%>

Directive lead-in: <%@

The JET directive lead-in can be escaped by placing a backslash (\) before the % sign:

JET template text:

<\%@NOT a JET Directive%>

Template output:

<%@NOT a JET Directive%>

Embedded XPath expression lead-in: ${

The embedded XPath lead-in can be escaped by putting part or all of the lead-in into an enclosing embedded XPath expression that returns a string.

JET template text. Here ${'$'} is an embedded XPath expression ('$'), which returns a single character $:

The minimum needed: ${'$'}{someStaticText}

Template output:

The minimum needed: ${someStaticText}

JET template text. Here, an embedded XPath expression returns the entire string ${someStaticText}:

An alternative - quote the entire expression: ${'${someStaticText}'}

Template output:

An alternative - quote the entire expression: ${someStaticText}

Back to the top