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..

2 Answers 2

2

In your controller hit:

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

In the view put:

<?php echo ($this->myParam != '') ? 'active' : 'non-active'; ?> 
Sign up to request clarification or add additional context in comments.

Comments

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'); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.