简体   繁体   English

GSP中的窗格组件

[英]Paned components in GSP

So it looks like Grails' GSP does not have an include tag (correct me if I'm wrong). 因此,看来Grails的GSP没有包含标记(如果我输入错了,请纠正我)。 The closest thing to "include" is to use the render tag . 最接近“ include”的是使用render标签 There is also the include plugin . 还有一个include插件

In my case, I have a classic top-left-middle-right-bottom paned page. 就我而言,我有一个经典的左上中右下底部平移页面。 The top header or left side would include navigation. 顶部标题或左侧将包含导航。 The middle would be the content. 中间就是内容。 The right side might include ads. 右侧可能包含广告。 In the JSP version of my app, each pane except for the middle would be in their own JSP. 在我的应用程序的JSP版本中,除中间部分外,每个窗格都在其自己的JSP中。 I'd then include (using <jsp:include/> ) the various panels into my page. 然后,将各种面板包含(使用<jsp:include/> )到我的页面中。 Is this the right approach in GSP? 这是GSP中正确的方法吗?

What is the preferred pattern of accomplishing this in GSP? 在GSP中完成此操作的首选模式是什么?

Instead of importing or rendering your panes per-view, you probably want to use the layout functionality that grails provides (with SiteMesh). 您可能不想使用grails提供的布局功能(与SiteMesh一起),而不是按视图导入或呈现窗格。 If you want to apply the same layout to all of your pages (ie menu/content/ads), you can just modify grails-app/views/layouts/main.gsp to have the page elements you need and then the <g:layoutBody/> tag will be filled in by your regular views rendered by your controllers. 如果要对所有页面(即菜单/内容/广告)应用相同的布局,只需修改grails-app/views/layouts/main.gsp即可拥有所需的页面元素,然后<g:layoutBody/>标记将由控制器呈现的常规视图填充。 The main.gsp layout is provided by default and is the default layout for all (scaffolded and generated) views. main.gsp布局是默认提供的,并且是所有(脚手架和生成的)视图的默认布局。

If you need some pages to have the ads and others to not have them, you'll want to create a new layout in grails-app/views/layouts (eg main-ads.gsp ). 如果您需要某些页面包含广告,而另一些页面则不需要,则需要在grails-app/views/layouts创建新的grails-app/views/layouts (例如main-ads.gsp )。 Then, in the views that you wish to have the ads, in the <head></head> , you'll set the layout using <meta name="layout" content="main-ads.gsp"/> . 然后,在希望显示广告的视图的<head></head> ,使用<meta name="layout" content="main-ads.gsp"/>设置布局。

http://docs.codehaus.org/display/GRAILS/Views+and+Layouts http://docs.codehaus.org/display/GRAILS/Views+and+Layouts

Starting with Grails 1.1 there's now an <g:include> tag which pretty much exactly does what you want. 从Grails 1.1开始,现在有一个<g:include> tag ,它几乎可以完全满足您的要求。

It still makes sense to look into the above options re layout / templates since they will be more efficient in most cases. 在重新布局/模板中查看以上选项仍然有意义,因为它们在大多数情况下会更高效。

You are correct that the render tag can accomplish what you want to do. 您认为render标签可以完成您想做的事情是正确的。 Try it with templates, the key is to name them with an initial underscore. 尝试使用模板,关键是用一个下划线来命名它们。 This blog post should be helpful. 这篇博客文章应该会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM