RSM
RSM

Reputation: 15118

how to add stylesheet to my layout and pass values from view to layout

I am using zend framework.

My structure is (only included files and folders needed for this question):

application
  >configs
  >controllers
  >forms
  >images
  >layouts
    >scripts
      >layout.phtml
  >models
  >styles
    >style.css
  >views
    >scripts
      >index
        >index.phtml
  Bootstrap.php
docs
library
logs
public
test

I have got the layout working properly. However, I want to ask a couple of questions in order to get my set up perfect for the way I want it.

  1. Is application>styles a good place for the stylesheet to be? If not what's the recommended?
  2. How do i add the stylesheet to the layout?
  3. In my layout I have a title tag : <title>Text</title>. How do I pass values from my controllers to it?

Upvotes: 1

Views: 109

Answers (1)

FilmJ
FilmJ

Reputation: 2021

  1. Stylesheets need to be accessible from the browser, so typically you will put these somewhere in the public directory, such as public/css

  2. There are several ways, including placing rel tags in your view/layout, but my preferred option is to use the viewHelper within your controller:

    $this->view->headLink()->setStylesheet('/css/style.css'); Then your call to headLink() in the layout file will automatically include the stylesheet.

  3. The way I have done this is to use the Zend_Registry in the past. There may be better ways.

Upvotes: 1

Related Questions