没有任何功能与您描述的完全一样 - 能够简单地终止代码生成。您可以做一些事情来提供等效的功能:
1) 您可以在选择元素中执行测试,并使 when 元素的范围成为要执行的代码生成的剩余部分。如果您将测试放在 main.jet 中,则此范围可能是整个代码生成
// in main.jet:
<c:choose>
<c:when test="..a condition that should be true in order to continue..">
// include a template that drives all processing to be
// performed if the test resolves to true
<c:include template="" />
</c:when>
<c:otherwise>
// Log the failure to validate and don't process
<c:log severity="error">Describe the error here</c:log>
</c:otherwise>
</c:choose>
请注意,在这种用法中,选择元素类似于 if-then-else。
2) 与 (1) 基本相同,不同之处在于您将选择放在用于为文件生成文本/内容的模板中。不同之处在于这种用法不会阻止生成文件。它只是减少了写入该单个文件的内容。
// in a content-producing template:
<c:choose>
<c:when test="..a condition that should be true in order to continue..">
// Put the remainder of the template logic inside the
// scope of this when element
</c:when>
<c:otherwise>
// Log the failure to validate and don't process
<c:log severity="error">Describe the error here</c:log>
</c:otherwise>
</c:choose>
我认为这不是你要找的东西
3) 这是一个高级主题,但您可以编写一个自定义 JET 标签来执行这种条件处理。它就像一个 if 元素,但测试将在处理完内容后运行,并且只有在测试为真时才会包含在输出中。您可以测试在该处理期间可能设置的变量,以防止生成的代码的输出。我将把该标签的实现留给另一个问题。
我认为您想要做的是 (1) 的一种形式:对输入文件执行一组验证,这是您在 main.jet 中执行的第一个操作,然后使 main.jet 的其余部分有条件验证的结果。