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

5
  • The question is hard to understand. Can you try to clarify it? Commented Apr 30, 2011 at 22:41
  • Within his partial he wants to attach a script to the view it sounds like. Commented Apr 30, 2011 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. Commented Apr 30, 2011 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 . Commented May 1, 2011 at 0:21
  • Ah okay, it looks like your right, its just a different scope, as you can pass variables through to the partial. Commented May 1, 2011 at 2:49

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

3 Comments

not success to do it, var_dump(Zend_Layout::getMvcInstance())===null
Yeah , Are you using a layout? Im wondering if Zend_Layout will be null if not.
Also, Just out of curiosity, why do you need to attach the script within the partial, maybe theres another way to attack this problem?
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

Comments

0

try this work for me :D

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.