1

I'm trying to dynamically add content when a tab is clicked by echoing a view partial from the controller with a jQuery get, the data returns just fine but any headScript() declarations I make in that partial aren't being set in the page header, declarations made in other partials that are called from this view DO have the appendFile operation succeed. I'm assuming this is because there's some preDispatch happening on the page load that goes through partials and appends headScript items to the header that's not happening when I dynamically load the partial code from the ajax get:

$.ajax({ url: sourceUrl, method: 'get', beforeSend: function(){ $('a[href="'+href+'"]').addClass('load').tab('show'); }, success: function(data){ console.log(data); $("#"+tabID+"-content").html(data); $('a[href="'+href+'"]').removeClass('load'); }, error: function(data){ $("#"+tabID+"-content").html('There was an issue loading the tab. Please try again.'); $('a[href="'+href+'"]').removeClass('load'); } }); 

This calls an action that has no layout, and simply echoes a partial:

$this->_helper->_layout->disableLayout(); echo $this->view->partial('device/pool-graph.phtml', array('id' => $id)); 

any <?php $this->headScript()->appendFile(); ?> operations don't seem to append the javascript to the header, is there another way to do this besides including the basic <script src='/js/script.js'> tags in the partial? I'd rather not do that.

1 Answer 1

2

There's no preDispatch involved in the head script helper, calls to the helper simply 'queue up' script tags which are then output by an echo call like <?=$this->headScript()?> that you presumably have in your layout. Since your controller action is disabling the layout, this call never happens.

You said you didn't want to output script tags in your partial, but that's the simplest way to fix your problem. If you want to avoid this because you're using the partial elsewhere in the application, a slightly messier solution might be to output the script tags using the helper after your partial:

$this->_helper->_layout->disableLayout(); echo $this->view->partial('device/pool-graph.phtml', array('id' => $id)); echo $this->view->headScript(); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.