Location: PHPKode > scripts > HSTemplate > readme.html
<html>
	<head>
		<title>HSTemplate</title>
	</head>
	<body>
		<div id="wikiheader" style="margin-bottom:1em">

<span style="font-size:120%;font-weight:bold">Tutorial</span>
&nbsp;


<div style="font-style:italic; margin-top: 3px">Learn HSTemplate in 10 Minutes (Small tutorial)</div>

</div>
<div id="wikicontent">
<h3>Include the HSTemplate class library</h3><pre class="code" style="margin-left: 2em; padding: 0.5em; border-left: 3px solid #ccc">require_once(&#x27;HSTemplate/HSTemplate.class.php&#x27;);</pre><h3>Instantiate the HSTemplate object</h3><p>For options <tt>template_path</tt> and <tt>cache_path</tt> use full path to directory </p><pre class="code" style="margin-left: 2em; padding: 0.5em; border-left: 3px solid #ccc">/* HSTemplate initialization */
$options = array(
                &#x27;template_path&#x27; =&gt; &#x27;templates&#x27;,
                &#x27;cache_path&#x27;    =&gt; &#x27;cache&#x27;,
                &#x27;debug&#x27;         =&gt; false,
                );
                
$HSTemplate =&amp; new HSTemplate($options);</pre><h3>Instantiate the HSTemplateDisplay object</h3><pre class="code" style="margin-left: 2em; padding: 0.5em; border-left: 3px solid #ccc">// index page
$DisplayIndex = &amp; $HSTemplate-&gt;getDisplay(&#x27;index&#x27;);</pre><h3>Add Templates</h3><p>Directory structure: </p><pre class="code" style="margin-left: 2em; padding: 0.5em; border-left: 3px solid #ccc">\- templates (directory set as `template_path`)
   \- index  (by display name)
      |- header.html
      |- index.html
      |- footer.html</pre><p>Example: </p><pre class="code" style="margin-left: 2em; padding: 0.5em; border-left: 3px solid #ccc">// add templates
$DisplayIndex-&gt;addTemplate(&#x27;header&#x27;, &#x27;header.html&#x27;);
$DisplayIndex-&gt;addTemplate(&#x27;index&#x27; , &#x27;index.html&#x27; );
$DisplayIndex-&gt;addTemplate(&#x27;footer&#x27;, &#x27;footer.html&#x27;);</pre><h3>Assign Variables</h3><p>You can assign variable to &#x27;Global section&#x27; or to &#x27;Display section&#x27; or to &#x27;Template section&#x27;, priority: <ol><li>Global section </li><li>Display section </li><li>Template section </li></ol></p><p>Example: </p><pre class="code" style="margin-left: 2em; padding: 0.5em; border-left: 3px solid #ccc">// assign template variables
$DisplayIndex-&gt;assign(&#x27;template&#x27;,     &#x27;DISPLAY&#x27;,   &#x27;index&#x27;);
// assign display variables
$DisplayIndex-&gt;assign(&#x27;display&#x27;,     &#x27;DISPLAY&#x27;);
// assign global variables (for all display)
$HSTemplate-&gt;assignGlobal(&#x27;global&#x27;,  &#x27;GLOBAL&#x27;);</pre><h3>Templates</h3><pre class="code" style="margin-left: 2em; padding: 0.5em; border-left: 3px solid #ccc">&lt;h2&gt;Test 1&lt;/h2&gt;
Global   Variable: &lt;?=$global?&gt;&lt;br/&gt;
Display  Variable: &lt;?=$display?&gt;&lt;br/&gt;
Template Variable: &lt;?=$template?&gt;&lt;br/&gt;</pre><h3>Use Cache</h3><p>Call method setCache for enable cache for curent <tt>Display</tt> <ul><li>first argument is unique ID for cache (you can use <tt>$_SERVER[&#x27;REQUEST_URI&#x27;]</tt>) </li><li>second - it&#x27;s cache lifetime - default value 3600 seconds (1hour) </li></p><pre class="code" style="margin-left: 2em; padding: 0.5em; border-left: 3px solid #ccc">$DisplayContent-&gt;setCache(&#x27;test1&#x27;, 3600);
if (!$DisplayContent-&gt;isCached()) {
   $DisplayContent-&gt;addTemplate(&#x27;test1&#x27;, &#x27;test1.html&#x27;);
   $DisplayContent-&gt;assign(&#x27;time&#x27;,     date(&#x27;H:i:s&#x27;), &#x27;test1&#x27;);
}</pre></ul><h3>Display</h3><pre class="code" style="margin-left: 2em; padding: 0.5em; border-left: 3px solid #ccc">// display all non separated &#x27;display&#x27;
$HSTemplate-&gt;display();</pre>
</div>

 
</div>
	</body>
</html>
Return current item: HSTemplate