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

Marcin
  • 215,873
  • 14
  • 235
  • 294
Zippp
  • 448
  • 6
  • 17

3 Answers3

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 .

Poelinca Dorin
  • 9,577
  • 2
  • 39
  • 43
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.

Marcin
  • 215,873
  • 14
  • 235
  • 294
3

You can also set empty container like this:

$this->view->headLink()->setContainer(
    new Zend_View_Helper_Placeholder_Container()
);