title: Enable jQuery using with ZendX_JQuery in a view helper
body: <p>I am trying to activate jQuery through a view helper called within the layout.</p>
  
  <p>The problem is that jQuery is already called within the layout and thus renders the  include files, before it is defined in the view helper.</p>
  
  <p>Here are my scripts :</p>
  
  <p><strong>Layout.phtml</strong>:</p>
  
  <pre><code>&lt;?php echo $this-&gt;doctype(); ?&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;?php echo $this-&gt;headTitle() ?&gt;
      &lt;?php echo $this-&gt;headLink()-&gt;appendStylesheet('/css/base.css') ?&gt;
      &lt;?php echo $this-&gt;headMeta() ?&gt;
      &lt;?php echo $this-&gt;headStyle() ?&gt;
      &lt;?php echo $this-&gt;jQuery() ?&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
  [...]
      &lt;div id="droite" class="column grid_4"&gt;
          &lt;!-- Column 2 start --&gt;
          &lt;?php echo $this-&gt;render('partials/droite.phtml'); ?&gt;
          &lt;!-- Column 2 end --&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>partials/droite.phtml</strong>:</p>
  
  <pre><code>&lt;?=$this-&gt;rolelinks(); ?&gt;
  </code></pre>
  
  <p><strong>My_View_Helper_Rolelinks</strong>:</p>
  
  <pre><code>&lt;?php
  
  class My_View_Helper_Rolelinks extends Zend_View_Helper_Abstract
  {
  
      public function rolelinks()
      {
          if (Model_User::hasIdentity()) {
              $role = Model_User::getRole();
              if ($role === 'admin') {
                  return $this-&gt;view-&gt;partial('partials/droite_admin.phtml');
                  return;
              }
          } else {
              return '';
          }
      }
  }
  </code></pre>
  
  <p><strong>partials/droite_admin.phtml</strong>:</p>
  
  <pre><code>&lt;?php
  $this-&gt;jQuery()
      -&gt;UiEnable()
      -&gt;addJavascriptFile('/js/jquery.ui.datepicker-fr.js')
      -&gt;addJavascriptFile('/js/onload.js');
  ?&gt;
  
  &lt;div id="calendar"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>So.</p>
  
  <p>Not sure this is the right way to do it, but the main idea is to check if the user is admin to enable jQuery and display a datepicker (calendar).</p>
  
  <p>Thanks in advance for your help.</p>