Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 740
Zippp Avatar asked Jun 21 '11 10:06

Zippp


3 Answers

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 .

like image 92
Poelinca Dorin Avatar answered Oct 26 '22 07:10

Poelinca Dorin


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.

like image 24
Marcin Avatar answered Oct 26 '22 05:10

Marcin


You can also set empty container like this:

$this->view->headLink()->setContainer(
    new Zend_View_Helper_Placeholder_Container()
);
like image 20
Sandi Verdev Avatar answered Oct 26 '22 06:10

Sandi Verdev