phpsymfonysymfony-1.4diem-cms

"Global" layout area in Diem, Symfony cms


Is it possible to have something like global area which would be displayed in every layout template the same way? i.e. if I have:

<?php echo $helper->renderArea('global.bottom', '.clearfix') ?>

in a few different layout files (pageSuccess.php, customPageSuccess.php, homePageSuccess.php, etcSuccess.php)

Whenever I change something in this area for one of them, it changes for all of them. Lets say, I add a new Zone and a new Text widget to this area in any page using pageSuccess.php layout, and the changes are displayed in every layout using this global area.

Is it possible?


Solution

  • So you say you need to have some code in some templates that will render in the exact same way for those templates.

    My advise would be, use slots. For example, you have this templates: helloSuccess.php and goodbyeSuccess.php but in both you need to show something (lets say the current time). So, you dont want to show it everywhere on the site but some of the templates may need it.

    You could have a layout.php (the main app layout template) look something like this:

    <html>
    <head>
    {....}
    </head>
    <body>
      <div id="special_container">
        <?php if(has_slot("time")):?>
          <?php include_slot("time")?>
        <?php endif?>
      </div>
      <div class="container">
        <?php echo $sf_content ?>
      </div>
    </body>
    </html>
    

    Then, each template that want to render something in the "special_container" should implement the slot "time". So back to the example, helloSuccess.php and goodbyeSuccess.php should have on their code something like this:

    <?php slot('time') ?>
      <!-- custom sidebar code for the current template-->
      <h1>Time </h1>
      <p>name:  <?php echo date("D M d, Y G:i a"); ?></p>
    <?php end_slot() ?>
    

    For more information on slots, components, partials i would really recommend this link: Inside the View Layer its symfony 1.2 but its quite the same for almost every symfony version previous to 2.0