简体   繁体   English

CakePHP - 创建2个$ content_for_layout变量

[英]CakePHP - Creating 2 $content_for_layout variables

I am working on a complete redesign for my company and I have run into a problem. 我正在为我的公司进行彻底的重新设计,我遇到了一个问题。 We are building if off the Cake Framework (1.2.0.7296 RC2) and I am trying to find the best solution to create a solid layout template. 我们正在构建如果离开Cake Framework(1.2.0.7296 RC2)并且我正在尝试找到创建实体布局模板的最佳解决方案。 The design I have created has multiple wrappers throughout each page. 我创建的设计在每个页面中都有多个包装器。 Below is a simplified version of the code. 下面是代码的简化版本。

<body style="background:url(somebackground.png);">
    <div class="page">
    <!--Page is used to constrain the content within a specific width-->
        <div class="header">
        <div class="nav">

      </div><!--End Nav-->
    </div><!--End Header-->
    <div class="content">
      <!--This area contains a slideshow and other info that varies from page-to-page-->
    </div><!--End Content-->
 </div><!--End Page-->
 <div class="wrapper" style="background:url(someotherbackground.png);">
    <div class="page">
    <div class="content">
        <!--Additional content-->
    </div><!--End Content-->
  </div><!--End Page-->
 </div><!--End Wrapper-->
 </body>

The problem is that in a Cake layout there is only one $content_for_layout, which would work for most websites. 问题是在Cake布局中只有一个$ content_for_layout,这适用于大多数网站。 However, because of how I have structured things, it makes it difficult to take full advantage of the layout template. 但是,由于我的结构是如何构建的,因此很难充分利用布局模板。 The only solution I have thought of was as follows. 我想到的唯一解决方案如下。

  • Close the top div class='page after the header and then add another div class='page' underneath of it. 关闭标题后面的顶部div class ='页面,然后在其下面添加另一个div class ='page'。 That way I would be able to put the header and nav in elements and keep them only in the layout template. 这样我就可以将标题和导航放在元素中,并将它们仅保留在布局模板中。 The problem with that is I am not taking full advantage of the template, because I am still going to be repeating the a lot of the html. 问题是我没有充分利用模板,因为我仍然会重复很多html。

Ideally I would like to have 2 $content_for_layout. 理想情况下,我想要2 $ content_for_layout。 One for the content underneath the first page and another for the content on the second. 一个用于第一页下面的​​内容,另一个用于第二页上的内容。 That way I can use the layout template to the fullest. 这样我就可以充分利用布局模板。 Then on my page I would have a section where I can place the perspective content. 然后在我的页面上,我将有一个部分,我可以放置透视内容。 In my research for this problem I found some solutions. 在我对这个问题的研究中,我找到了一些解决方案

I am not sure if these are the best solutions or are going to give me what I am looking for. 我不确定这些是最好的解决方案还是会给我我想要的东西。 I am a designer and frontend developer, so my knowledge of Php is limited. 我是一名设计师和前端开发人员,因此我对Php的了解有限。 My knowledge of Cake is even more limited. 我对蛋糕的了解更加有限。 I am looking for the simplest solution. 我正在寻找最简单的解决方案。

If that is possible (but I'm assuming not), use the latest version of Cake (2.2.1 stable). 如果可能(但我假设没有),请使用最新版本的Cake(2.2.1稳定版)。 Since 2.1, Cake supports View Blocks , that solve the exact problem you're having. 从2.1开始,Cake支持View Blocks ,它可以解决您遇到的确切问题。

If it's not possible, you could set some variable (maybe a rendered Element, or, better yet, the variables you'd have to forward to an element rendered from the layout) from your Controller, and echo that wherever you want on the layout. 如果不可能,您可以从Controller中设置一些变量(可能是渲染的元素,或者更好的是,您必须将变量转发到从布局渲染的元素),并在布局中的任何位置回显。 All variables you pass from Controller to View with Controller::set will be available to the layout as well. 您从Controller传递到View with Controller::set所有变量也可用于布局。

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

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