3

How can javascript file + javascript code inserted to partial for head or body area?

[Inside view simply call for insert to head to HeadScript and to body InlineScript - this not works inside partial(If I am wrong please write). ]

Thanks,

Yosef

Charles
  • 50,943
  • 13
  • 104
  • 142
Ben
  • 25,389
  • 34
  • 109
  • 165
  • The question is hard to understand. Can you try to clarify it? – Jani Hartikainen Apr 30 '11 at 22:41
  • Within his partial he wants to attach a script to the view it sounds like. – Bodman Apr 30 '11 at 22:42
  • It looks like partials have their own scope, and dont "seem" to have access to the view. I may be wrong tho. From what it sounds like, instead of using a partial, you should be using a custom view helper. – Bodman Apr 30 '11 at 22:54
  • Partials have the same scope as the calling view script, so the following works as expected (clean copy of ZF 1.11.5): bin/zf.sh create project . – cmbuckley May 01 '11 at 00:21
  • Ah okay, it looks like your right, its just a different scope, as you can pass variables through to the partial. – Bodman May 01 '11 at 02:49

3 Answers3

1

I have not tried this, but have you tried using the following code inside your partial

$view = Zend_Layout::getMvcInstance()->getView();

$view->headScript()->appendFile('/scripts/somefile.js');

I know you were saying it doesn't work, but maybe its the method your getting your view instance?

In theory it should work.

Bodman
  • 7,938
  • 3
  • 29
  • 34
  • not success to do it, var_dump(Zend_Layout::getMvcInstance())===null – Ben May 01 '11 at 19:30
  • Yeah , Are you using a layout? Im wondering if Zend_Layout will be null if not. – Bodman May 02 '11 at 01:18
  • Also, Just out of curiosity, why do you need to attach the script within the partial, maybe theres another way to attack this problem? – Bodman May 02 '11 at 01:24
0

I know this is far out of date, but maybe other like me having the same problem:

Make sure that you render your partial BEFORE you echo your headscript/links ;) Took a while to figure out,.. but it does have some degree of logic in it :p

Flip Vernooij
  • 889
  • 6
  • 15
0

try this work for me :D

<?php echo '<?php $this->headScript()->appendFile ($this->baseUrl(). "/js/jquery.jplayer.min.js" );?>';?>