Change bootstrap container for individual pages

So I want to use container-fluid instead of just ‘container’ for only 1 particular view - does anyone know how to do that ?

The easiest ways off the top of my head are (there are a couple more difficult and I’m sure others but I’m only posting three):

[list=1][]Create a new layout for it and tell the controller to use it.[]Don’t include container-fluid in the main layout and put it in the views[*]Put if check in the div to use either of the two classes[/list]

I’d just create a new layout in your views/layouts (i’d copy the one that you just need the class changed) folder for the view that needs changed and put tell the controller action to use it.




public function actionSomeAction{

  $this->layout='yourNewLayout';

}

worked perfectly, thanks!

For others who might look to do the same, i simply copied the /layouts/main.php to /layouts/main-fluid.php

In main-fluid.php, all I changed was <div class="container"> to <div class="container-fluid"> everything else unchanged.

So then, in the action that renders the view I want to be fluid, I add $this->layout = ‘main-fluid’;

thanks

just thinking about this - my only issue is that now, when i change the main layout, I will need to remember to always change it in both main layout files. Not ideal - if anyone has any better ideas, please post :)

Skworden has already recommended an alternative:

If there’s only a single div element that needs to be changed you can simply do




<div class="<?= isset($this->params['isFluid']) && $this->params['isFluid'] ? 'container-fluid' : 'container' ?>">

</div>



and in view template




<?php $this->params['isFluid'] = true; ?>



Glad it worked

You can do the if check like phtamas said.

you can also use require statements for things like your header, footer, menu etc.

[size="2"]




 <head>

      $this->render('//layouts/header.php');

</head>



[/size]

[size="2"]and put your header stuff in header.php in your layouts folder. You can use that for all of your layouts that that applies to.

[/size]

[size="2"]that way when you change the header for one layout it will change it for all of them.[/size]