addHeaderItem() from theme template

Permalink
So I've been searching high and low for an answer that I thought would be rather simple. Sifted through countless forum posts on this topic but have not found a working solution.

I have a template that I would like to load some javascript files and some css files. These files are specific to only one theme template, not for the entire theme and not for a block.

In the template file I assumed the following would work:
$this->addHeaderItem('<script src="'.BASE_URL.DIR_REL.'/themes/my_theme/js/my_script.js" type="text/javascript" />', "VIEW");

However, as I have learned, this is "added" to the header after the header has been output.

Is there a way to add an item to the header from a theme template file?

ijessup
 
Remo replied on at Permalink Reply
Remo
yes, just name it view.css

if you create a new template, instead of mytemplate.php create a directory with the name "mytemplate" and put view.php and view.css into that directory
ijessup replied on at Permalink Reply
ijessup
Thanks Remo.

Unfortunately, its an existing template that needs modification.

That was my original thought but the page reverts to the default.php template and not the ~/themes/my_theme/my_template/view.php file. And I can't find any where in the DB that specifies what file should be used for the page type's template file other than its handle.

Ideas?

Thanks again,
- Isaac
ijessup replied on at Permalink Reply
ijessup
Seems I have dyslexia. I had scr="..." rather than src="...


>.<
ScottC replied on at Permalink Reply
ScottC
also helps to grab an instance. $v = View::getInstance();
$v->addHeaderItem('js string via htmlhelper or otherwise','CONTROLLER'); //if you need to make sure it is loaded last say with foxycart or something.