title: php encoded json to template and javascript
body: <p>I'm using Codeigniter and Smarty (template engine) and therefore using templates.</p>
  
  <p>I have a method that calls the template which has all html, css and js functions:</p>
  
  <pre><code>public function index()
  {
      //dashboard text
      $this-&gt;data['title'] = 'Dashboard';
      $this-&gt;data['subtitle'] = 'feeds, users, and more';
  
      //load the donut graph data
      $fbyg = $this-&gt;feed_model-&gt;countFeedsByGroups();
      echo json_encode($fbyg);
  
      //parses the dashboard template
      $this-&gt;smartyci-&gt;display('dashboard.tpl', $this-&gt;data);
  }
  </code></pre>
  
  <p>the thing is that I need to send some information to one of the js files bounded to my dashboard.tpl in order to render a graphic.</p>
  
  <p>So I know I have to encode the php array into jSon object and send it to the template. But, how do I do this when I have not only to send and echo with the json but also I have to display my template sending for it other information?</p>
  
  <p>The other question is, How do I receive the json and get the data? I'm trying and so far no results:</p>
  
  <p>From my dashboard.tpl:</p>
  
  <pre><code>    &lt;script src="{site_url()}application/views/js/test.js"&gt;&lt;/script&gt;
      &lt;script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js'&gt;&lt;/script&gt;
  </code></pre>
  
  <p>From test.js:</p>
  
  <pre><code>$.getJSON('admin.php', function(data) {
      console.log(data.vgro_name);
  });    
  </code></pre>