Question

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. 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. 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. 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.

Ideally I would like to have 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. My knowledge of Cake is even more limited. I am looking for the simplest solution.

Was it helpful?

Solution

If that is possible (but I'm assuming not), use the latest version of Cake (2.2.1 stable). Since 2.1, Cake supports View Blocks, that solve the exact problem you're having.

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. All variables you pass from Controller to View with Controller::set will be available to the layout as well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top