Search code examples
phpsymfony1

How can you pass a parameter from an action to the layout in Symfony


The global layout.php file contains the tags for each page:

<body> 
    <?php echo $sf_content ?>
</body>

But for all my inner HTML pages of the site, a class is applied to the body tag:

 <body class="inner-page"> 
    <?php echo $sf_content ?>
 </body>

How can I pass in a class to the layout from different templates?


Solution

  • in your layout.php

    <body <?php if (!include_slot('body_id')): ?>id="default"<?php endif; ?>>
    

    in your templates :

    <?php slot('body_id') ?>id="bla"<?php end_slot(); ?>
    

    or

    <?php slot(
      'body_id',
      sprintf('id="%s"', $sf_params->get('module')))
    ?>