[英]activeweb ContentFor tag render nothing?
I have read content for and yield tag
section of activeweb doc. 我已经阅读了activeweb文档的
content for and yield tag
部分。 and activeweb version 和activeweb版本
16:59 $ mvn dependency:tree | grep activeweb
[INFO] +- org.javalite:activeweb:jar:2.2:compile
[INFO] +- org.javalite:activeweb-testing:jar:2.2:test
The layout.ftl
template code lists below: layout.ftl
模板代码如下:
{
"ext": [<@yield to="ext"/>],
"data": ${page_content}
}
and the view page: 和视图页面:
<@content for="ext">
"hello", "world"
</@content>
["this is data"]
I run the controller and ext
render nothing. 我运行控制器,并且
ext
渲染任何内容。 Did I miss something? 我错过了什么?
BTW, how can I check the ContentForTag
contain some content or not?, I want the layout.ftl look like 顺便说一句,如何检查
ContentForTag
包含某些内容?我希望layout.ftl看起来像
{
<#if ext?has_content?>
"ext": [<@yield to="ext"/>],
</#if>
"data": ${page_content}
}
you have a two part question: 您有一个两部分的问题:
To answer your first question, I can say not sure why it is not working for you. 要回答您的第一个问题,我不能确定为什么它对您不起作用。 I created an identical example based on your code, and it is working as expected.
我根据您的代码创建了一个相同的示例,它按预期运行。 Please, see the last commit on ActiveWeb Simple project
content_for
branch: https://github.com/javalite/activeweb-simple/tree/content_for You can run this project to see that your code is working. 请查看ActiveWeb Simple项目
content_for
分支上的最后一次提交: https : //github.com/javalite/activeweb-simple/tree/content_for您可以运行该项目以查看您的代码是否正常运行。
TO answer your second question, you need to use a condition in the view, not in the layout. 要回答第二个问题,您需要在视图中而不是在布局中使用条件。 So, the view would look like this:
因此,视图将如下所示:
<#if condition >
<@content for="ext">
"hello", "world"
</@content>
["this is data"]
</#if>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.