Zend Framework: How to unset the one stylesheet from the HeadLink helper
Asked Answered
S

3

6

I have in Controller init() a list of common styles:

$this->view->headLink()->setStylesheet('/style/style.css');
$this->view->headLink()->appendStylesheet('/style/style2.css');
$this->view->headLink()->appendStylesheet('/style/style3.css');
$this->view->headLink()->appendStylesheet('/style/forms.css');
$this->view->headLink()->appendStylesheet('/style/ie_patches.css','all','lte IE 7');

what I need is the way to remove one of the stylesheets from the stack later in one of the action of this controller.

Appreciate your help, excuse my English

Szabadka answered 21/6, 2011 at 10:26 Comment(0)
A
7

OR you can use

$this->view->headLink()->offsetUnset($offsetToBeRemoved); // offsetToBeRemoved should be integer

To find out the offsetToBeRemoved you can either get the iterator ( $this->view->headLink()->getIterator() ) or the container $this->view->headLink()->getContainer() ), loop thru it and get the key you're intrested in .

Adverb answered 21/6, 2011 at 10:53 Comment(0)
A
4

For example, if you want to remove '/style/style2.css' you can do in an action as follows:

    $headLinkContainer = $this->view->headLink()->getContainer();
    unset($headLinkContainer[1]);

This works because the container (i.e. instance of Zend_View_Helper_Placeholder_Container) extends ArrayObject. This means that you can manipulate your headLink elements as if you were using an array.

Hope this helps.

Agential answered 21/6, 2011 at 10:51 Comment(0)
J
3

You can also set empty container like this:

$this->view->headLink()->setContainer(
    new Zend_View_Helper_Placeholder_Container()
);
Jinny answered 20/2, 2012 at 1:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.