Note that there are some explanatory texts on larger screens.

plurals
  1. POfetch templates from database/string
    primarykey
    data
    text
    <p>I store my templates as files, and would like to have the opportunity to store them also in a MySql db.</p> <p><strong>My template System</strong></p> <pre><code>//function of Template class, where $file is a path to a file function fetch() { ob_start(); if (is_array($this-&gt;vars)) extract($this-&gt;vars); include($file); $contents = ob_get_contents(); ob_end_clean(); return $contents; } function set($name, $value) { $this-&gt;vars[$name] = is_object($value) ? $value-&gt;fetch() : $value; } </code></pre> <p><em>usage:</em></p> <pre><code>$tpl = &amp; new Template('path/to/template'); $tpl-&gt;set('titel', $titel); </code></pre> <p><em>Template example:</em></p> <pre><code>&lt;h1&gt;&lt;?=titel?&gt;&lt;/h1&gt; &lt;p&gt;Lorem ipsum...&lt;/p&gt; </code></pre> <p><strong>My approach</strong></p> <ol> <li>Selecting the the template from the database as a String</li> <li>what i got is like $tpl = "&lt;<em>h1>&lt;</em>?=$titel? >...";</li> <li>Now I would like to pass it to the template system, so I extended my constructor and the fetch function:</li> </ol> <p>function fetch() {</p> <pre><code>if (is_array($this-&gt;vars)) extract($this-&gt;vars); ob_start(); if(is_file($file)){ include($file); }else{ //first idea: eval ($file); //second idea: print $file; } $contents = ob_get_contents(); ob_end_clean(); return $contents; } </code></pre> <p>'eval' gives me an Parsing exception, because it interprets the whole String as php, not just the php part. 'print' is really strange: It doesn't print the staff between , but I can see it in the source code of the page. php function are beeing ignored.</p> <p>So what should I try instead? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload