1

I would like to inject a css on a header, on a specific view. I've looked into Zend manual and it talks about some sort of helper class for doing so. However, I'm not sure if we have all helpers available to us.

Do we have that helper class always available?

What would be an example of doing such a thing?

2 Answers 2

10

It's one of the core helpers, so you'll definitely have it available unless you've got a very exotic setup. From the manual, typically you'll want to do something like:

$styles = 'div#myDiv{margin:10px;padding:10px;}';
$this->headStyle()->appendStyle($styles);

in your view file to initialise your style. In your layout file you'll need to then echo out what you've appended using:

echo $this->headStyle();

Note that both the initialising and that final echo are required.

Edit: this assumes you're doing it inline - if you want to inject a linked CSS file then you'll use the headlink helper; that's the same deal, you initialise it and then echo it out in your layout.

Sign up to request clarification or add additional context in comments.

2 Comments

care to give an example of the last case please? With inject linked CSS file. :)
Looks like you got this while I was asleep in bed ;) but the syntax is as per yvoyer's answer below for any future searchers.
6
$this->headLink()->appendStylesheet('/css/style.css');

2 Comments

Got it: echo $this->headLink(); - Regards. ;)
If you have short PHP tags enabled, then you can do "<?= $this->headLink()->appendStylesheet('/css/style.css'); ?>" instead of an echo.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.