0

I have a basic layout.phtml script that I use on every page. Now I would like to add an active class to the page loaded. So I would like to do like this:

class=" if route ends with = ''? active : not-active "

How can I do this in a ZF view?

I need this because I have a page with 4 links to the same action but different parameters and I want to see wich one is selected..

nielsv
  • 6,540
  • 35
  • 111
  • 215

2 Answers2

2

In your controller hit:

$this->view->assign('myParam', $this->getRequest()->getParam('yourParam', ''));

In the view put:

<?php echo ($this->myParam != '') ? 'active' : 'non-active'; ?>
Daniel W.
  • 31,164
  • 13
  • 93
  • 151
0

So the class you would like to add is in layout but you want to send the content form the particular embedded view script

Placeholders were meant for this purpose http://framework.zend.com/manual/1.12/en/zend.view.helpers.html#zend.view.helpers.initial.placeholder

So in layout you would do something like for instance

<body class="<?php echo $this->placeholder('bodyClasses') ?>">

then in your viewscript you can do for example

$this->placeholder('bodyClasses')
    ->set('nameofpage');
Shaun Hare
  • 3,771
  • 2
  • 24
  • 36