-- flow <[email protected]> wrote
(on Wednesday, 05 August 2009, 02:47 AM -0700):
> I got a .js file which I want to include in a specific view.
> I thought I can include it with
> 
> $this->headScript()->appendFile($this->baseUrl() . '/js/script.js')
> 
> but this way the file is included in the content section, not in the header
> section.
> 
> How could I include it into the header section?

headScript() aggregates information. When you call it without
echoing it, it simply acts as a container. Later, you should echo it
within the <head> of your layout view script.

As an example, take the following directory structure:

    application/
    |-- layouts/
    |   `-- scripts/
    |   |   `-- layout.phtml
    |-- views/
    |   `-- scripts/
    |   |   `-- foo
    |   |   |   `-- bar.phtml

In views/scripts/foo/bar.phtml, you would have your call as above:

    $this->headScript()->appendFile($this->baseUrl() . '/js/script.js')

Then, in your layout script, you'd do this:
    
    <head>
        ...
        <?php echo $this->headScript() ?>
        ...
    </head>

-- 
Matthew Weier O'Phinney
Project Lead            | [email protected]
Zend Framework          | http://framework.zend.com/

Reply via email to