Answers.Body: <p>You can create a custom plugin to fetch the data. <a href="http://pluginfactory.io/" rel="nofollow noreferrer">Pluginfactory.io</a> is a good place to create your basic files/folders. Then you'll insert this function in your <code>PluginVariable</code>.</p>
  
  <pre><code>public function getData($table){
      return craft()-&gt;db-&gt;createCommand()
          -&gt;select('*')
          -&gt;from($table)
          -&gt;where('some Conditions)
          -&gt;queryAll();
  }
  </code></pre>
  
  <p>and in your template </p>
  
  <pre><code>{% for entry in craft.pluginName.getData('xyz') %}
      {{ entry.someField }}
  {% endfor %}
  </code></pre>
  
  <p>Note: this only works when the table prefix is the same as your craft tables. So before your <code>from($table)</code> Craft will automatically include a <code>$tablePrefix</code> (usually craft_) you can either name your custom tables <code>craft_</code> as well or change the prefix before your query </p>
  
  <pre><code>$oldPrefix = craft()-&gt;db-&gt;tablePrefix;
  craft()-&gt;db-&gt;tablePrefix = '';
  // handle your queries
  craft()-&gt;db-&gt;tablePrefix = $oldPrefix;
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-24T09:40:00.320Z
Answers.LastActivityDate: 2018-01-24T09:40:00.320Z
Answers.UserDisplayName: Robin Schambach
Body: <p>I have a Craft CMS installation in which there will be other data imported into the db (via Cronjob). It's data from a Weatherstation which will be displayed without further editing in the Control Panel. </p>
  
  <p>Is it possible to display this data via Twig bypassing the Control Panel all-together?</p>
  
  <p>something like:</p>
  
  <pre><code>{% for entry in special.db.section('xyz') %}
    {{ entry.value }}
  {% endfor %}
  </code></pre>
  
  <p>My first thought would be to do this via the <a href="https://github.com/craftcms/element-api" rel="nofollow noreferrer">Element API Plugin</a> and then use JavaScript to display this data. But maybe that's not necessary?</p>
  
Tags: <templating><database>
Title: Display non Craft CMS data with Twig
ThreadText: # Display non Craft CMS data with Twig
  
  (Asked by: username_0 on 2018-01-24)
  
  I have a Craft CMS installation in which there will be other data imported into the db (via Cronjob). It's data from a Weatherstation which will be displayed without further editing in the Control Panel.
  
  Is it possible to display this data via Twig bypassing the Control Panel all-together?
  
  something like:
  
  ```
  {% for entry in special.db.section('xyz') %}
    {{ entry.value }}
  {% endfor %}
  
  ```
  
  My first thought would be to do this via the [Element API Plugin](https://github.com/craftcms/element-api) and then use JavaScript to display this data. But maybe that's not necessary?
  
  **Tags:** templating, database
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-01-24. Score: 3 | Accepted answer
  
  You can create a custom plugin to fetch the data. [Pluginfactory.io](http://pluginfactory.io/) is a good place to create your basic files/folders. Then you'll insert this function in your `PluginVariable`.
  
  ```
  public function getData($table){
      return craft()->db->createCommand()
          ->select('*')
          ->from($table)
          ->where('some Conditions)
          ->queryAll();
  }
  
  ```
  
  and in your template
  
  ```
  {% for entry in craft.pluginName.getData('xyz') %}
      {{ entry.someField }}
  {% endfor %}
  
  ```
  
  Note: this only works when the table prefix is the same as your craft tables. So before your `from($table)` Craft will automatically include a `$tablePrefix` (usually craft\_) you can either name your custom tables `craft_` as well or change the prefix before your query
  
  ```
  $oldPrefix = craft()->db->tablePrefix;
  craft()->db->tablePrefix = '';
  // handle your queries
  craft()->db->tablePrefix = $oldPrefix;
  
  ```
  
  
  ---
  
  