doLayout和'Java Play!'中的模板包含有什么区别? [英] What is the difference between doLayout and include in a template in 'Java Play!'?

查看:170
本文介绍了doLayout和'Java Play!'中的模板包含有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 doLayout 扩展时,您只能拥有一个子模板,但可以包含不止一个。

When extending with doLayout you can only have one sub-template, but you can include more than one.

有什么区别,最佳做法是什么?

What is the difference, and what is the best practice?

推荐答案

它们彼此相反。

doLayout 用作<$ c $的一部分c> extends 标签。 extends标记指定您希望扩展的模板, doLayout 标记指定扩展模板中注入代码的位置。

doLayout is used as part of the extends tag. The extends tag specifies which template you wish to extend, and the doLayout tag specifies where in the extended template your code is injected.

include 标签只是指定应在指定点注入另一个模板。

The include tag simply specifies that another template should be injected at the point specified.

所以, doLayout以类似的方式工作,除了doLayout标记没有指定注入哪个模板。这是由extends标签完成的,这意味着模板(通常包含页眉,页脚和常见的css和javascript)可以扩展,而不需要知道任何有关扩展它的模板的信息。

So, doLayout works in a similar way to include, except the doLayout tag does not specify which template is being injected. This is done by the extends tag, and means that the template (which usually contains headers, footers and common css and javascript), can be extended without it needing to know anything about the template that is extending it.

包含,只是一个愚蠢的代码注入。

Include, is just a dumb injection of code.

如果你想要要使用includes实现doLayout功能(这是你在PHP或类似的东西中实现的方式),你可以做到

If you wanted to achieve the doLayout functionality with includes (and this is the way you would do it in PHP or something similar), you could do

#{include 'header.html'}
your template code
#{include 'footer.html'}

这必须在模板的每个页面上复制。使用 extends doLayout 允许你只需

This would have to be replicated on every page in your template. Whereas using extends and doLayout allows you to simply do

#{extends 'template.html'}

您的代码注入到template.html中,由doLayout标记管理。

And where your code is injected into the template.html is managed by the doLayout tag.

扩展方法只是一种更简洁的方法。此外,如果您决定更改页面布局,则只需更新一个文件,并在内容位于扩展模板中的位置提供更大的灵活性。

The extends approach is simply a neater way. Also, if you decide to change the layout of your page, you only need to update one file, and gives your more flexibility with where you content is located inside your extended template.

这篇关于doLayout和'Java Play!'中的模板包含有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆