移动父块的优雅方式
我有一个像这样的父模板:
{block "body"}{block "message"}Some stuff{/block}{/block}
以及一个像这样扩展所述父模板的模板:
{extends "parent.tpl"}
{block "body"}
Some content...
{block "message"}{$smarty.block.parent}{/block}
{/block}
并且其中有 {block "message"}{$smarty.block.parent}{/block}
我会喜欢将父块的内容移动到那里 - 基本上,如果模板扩展父块,则消息应该显示在正文中,但如果它扩展子块,则应该显示在其他区域。有没有一个好的方法可以用 Smarty 模板来解决这个问题?
I have a parent template like so:
{block "body"}{block "message"}Some stuff{/block}{/block}
and a template that extends said parent template like so:
{extends "parent.tpl"}
{block "body"}
Some content...
{block "message"}{$smarty.block.parent}{/block}
{/block}
and where there's {block "message"}{$smarty.block.parent}{/block}
I'd like to move the contents of the parent block there instead - basically, if a template extends the parent, the message should be displayed right in the body, but if it extends the child, it should be displayed in some other area. Is there a nice way to tackle this problem with Smarty templates?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定我是否理解正确。如果在子级中定义了“body”,是否要在“body”块之外显示“message”块的内容?
这可以按如下方式完成:
和
I'm not sure if I did understand it right. Do you want to display the content of the the "message" block outside the "body" block if "body" is defined in the child?
This could be done as follow:
and