Question

I have a small number of styles set with $this->headLink()->appendStylesheet() on the layout and I am trying to append another stylesheet from inside a view. However, the stylesheet from the view is always the first one rendered in the headLink stack.

layout.phtml:

echo $this->headLink()->appendStylesheet($this->basePath('css/styleA.css'))
                      ->appendStylesheet($this->basePath('css/styleB.css'));

Then in the view I've tried the following

view.phtml:

$this->headLink()->appendStylesheet($this->basePath('css/sub/styleC.css'));

and

$this->headLink()->offsetSetStylesheet(100, $this->basePath('css/sub/styleC.css'));

However, both end up with styleC being the first link tag that is rendered. I understand that child views are rendered first (ie, view.phtml is rendered before layout.phtml), but I thought helpers like headLink and headScript have a shared stack as long as the renderer is the same. Is this assumption wrong?

Was it helpful?

Solution

You need to prepend your stylesheets in layout, e.g.:

echo $this->headLink()->prependStylesheet($this->basePath('css/styleB.css'))
                      ->prependStylesheet($this->basePath('css/styleA.css'));

and append stylesheets in view as you do it before.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top