Changing a specific class in default.ctp

Below is my file default.ctp

. My question is, how do I change class="post-content"

from a different view or page?

   <main class="main-content">
          <div class="post-content"> 
            <?php echo $this->Session->flash(); ?>
            <?php echo $this->fetch('content'); ?>  
          </div>            
   </main>

      

+3


source to share


1 answer


In your layout, you can modify the static class to include the simple if / else statement shown below:

<main class="main-content">
    <div class="<?php echo (isset($layout_class_var)) ? $layout_class_var : 'post-content'; ?>"> 
        <?php echo $this->Session->flash(); ?>
        <?php echo $this->fetch('content'); ?>  
    </div>            
</main>

      



Then, every time you want to set a new class name instead of the default post-content class , just set the class name you want in the $ layout_class_var variable on your controller action:

public function someAction() {
    //set layout class to 'new-layout-class'
    $this->set('layout_class_var', 'new-layout-class');
}

      

+2


source







All Articles