How do I keep my CSS links in the head section for Zend?
I want to have action specific CSS, meaning that it would only link the CSS for the actions that uses it (also for my jQuery stuff). Currently, I am just putting $this->headLink()->appendStylesheet('/styles/basic.css')
in the view file of the action that needs the CSS. However, when I look at the source, it's just out of place and I want it to be in the head section. I can开发者_开发百科 load it up in the bootstrap, but I do not want to link unnecessary things for unrelated actions. Is there a way for me to load my action-specific CSS in the head section?
Pretty simply, do not ECHO $this->headLink()->appendStylesheet($css)
in your view. Personally i only do one <?=$this->headLink()?>
in my layout.phtml and in all other files its just appending the headLink without echoing it.
Hi you can place the headlink in your actions of controller for example
here is your action
public function indexAction()
{
$this->view->headLink()->appendStylesheet('/styles/basic.css');
}
The other way to place the head link in your view as you have done. Its up to you how you use this. Then in
<head>of your layout you can just echo your
headlink
like this
echo $this->headStyle();
On your head section just
<?php echo $this->headLink(); ?> //for css
if you want to link js files then
<?php echo $this->headScript() ; ?> // for js
Appending file in the phtml side
<?php $this->headScript()->appendFile($this->baseUrl.'/js/yourjs.js'); ?> //js
<?php $this->headLink()->appendStylesheet($this->baseUrl.'/css/yourcss.css');?> // css
精彩评论