简体   繁体   English

如何在舒适的墨西哥沙发中呈现嵌套子页面

[英]How to render nested child pages in Comfortable Mexican Sofa

So this is what I'm trying to accomplish, but I'm not sure where to start: 所以这就是我想要完成的,但是我不确定从哪里开始:

I have the following structure of pages: 我的页面结构如下: 在此处输入图片说明

On the home page, I want to display each child to of Publications as a section. 在主页上,我想将“出版物”的每个子项显示为一个部分。 The two sections would be Alerts, and New Story of the Week. 这两个部分是“警报”和“本周新故事”。 Then the latest published child of a section would render within that section. 然后,该部分的最新发布子项将在该部分中呈现。 So on home page I would have the following sections and articles: Alerts -> Trouble in the East-1-20-2015 News Story of the Week -> Congress Ohverhauls Farm Bill 因此,在主页上,我将包含以下部分和文章:警报-> 2015年1月20日东部新闻中的问题->国会Ohverhauls农场法案

I've read the CMS wiki, but I don't know how to approach this. 我已经阅读了CMS Wiki,但是我不知道该如何处理。 Do I use tags and collections? 我是否使用标签和集合?

You'll need to create a partial to get this working. 您需要创建一个局部零件才能使此工作正常进行。

Create one here /app/views/comfy/cms/content/_section_list.html.erb 在此处创建一个/app/views/comfy/cms/content/_section_list.html.erb

Then in the layout for the homepage add {{cms:partial:section_list}} to the html where you want the partial to be displayed. 然后,在首页的布局中,将{{cms:partial:section_list}}添加到要显示部分内容的html中。

Then in _section_list.html.erb do something like: 然后在_section_list.html.erb执行以下操作:

<% @cms_page.children.each do |section| %>
  <h1><%= section.blocks.where(identifier: 'header').first.content %></h1>
  <%= section.children.first.blocks.where(identifier: 'content').first.content %>
<% end %>

Note: be sure to get the block identifiers correct, I'm assuming you have a header and content in the snippet above. 注意:请确保正确使用块标识符,我假设您在上面的代码段中具有headercontent

In cms layout that Publication is using define a partial tag {{ cms:partial:foo/bar/articles }} Publication使用的cms布局中,定义部分标签{{ cms:partial:foo/bar/articles }}

Inside that partial you'll have access to @cms_page . 在该部分中,您可以访问@cms_page Now you can render things out. 现在您可以渲染东西了。

@cms_page.children will give you Alerts and News Story of the Week pages. @cms_page.children将为您提供News Story of the Week AlertsNews Story of the Week页面。 Then you can fetch a first child of those pages. 然后,您可以获取这些页面的第一个孩子。

It's using acts_as_tree in the back, so it's pretty straightforward. 它在后面使用acts_as_tree ,因此非常简单。

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

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