<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Web Style Press, Best Practices from all the Web, Build Better Websites &#187; CMS</title>
	<atom:link href="http://www.webstylepress.com/tag/cms/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.webstylepress.com</link>
	<description>Web VS Style</description>
	<lastBuildDate>Mon, 26 Dec 2011 10:35:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Smarty For Smart Developers</title>
		<link>http://www.webstylepress.com/smarty-for-smart-developers/</link>
		<comments>http://www.webstylepress.com/smarty-for-smart-developers/#comments</comments>
		<pubDate>Sun, 26 Oct 2008 19:39:34 +0000</pubDate>
		<dc:creator>Hiroshi</dc:creator>
				<category><![CDATA[CMS]]></category>
		<category><![CDATA[smarty]]></category>

		<guid isPermaLink="false">http://www.webstylepress.com/?p=317</guid>
		<description><![CDATA[SMARTY &#8211; What &#038; Why SMARTY is a template engine for PHP. More specifically, it facilitates a manageable way to separate application logic and content from its presentation. This is best described in a situation where the application programmer and the template designer play different roles, or in most cases are not the same person. [...]<p><a href="http://www.webstylepress.com/smarty-for-smart-developers/">Smarty For Smart Developers</a> is a post from: <a href="http://www.webstylepress.com">Web Style Press, Best Practices from all the Web, Build Better Websites</a></p>
]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.webstylepress.com/wp-content/uploads/2008/10/smarty-logo.jpg" alt="" title="smarty-logo" width="250" height="66" class="alignnone size-full wp-image-318" /></p>
<h4>SMARTY &#8211; What &#038; Why</h4>
<p><a rel="nofollow" target="_blank" href="http://www.smarty.net/">SMARTY</a> is a template engine for PHP. More specifically, it facilitates a manageable way to separate application logic and content from its presentation. This is best described in a situation where the application programmer and the template designer play different roles, or in most cases are not the same person.</p>
<p><span id="more-317"></span></p>
<h5>Some of Smarty&#8217;s features</h5>
<ul>
<li>Smarty is extremely fast.</li>
<li>It is efficient since the PHP parser does the dirty work.</li>
<li>No template parsing overhead, only compiles once.</li>
<li>It is smart about recompiling only the template files that have changed.</li>
<li>You can easily create your own custom functions and variable modifiers, so the template language is extremely extensible.</li>
<li>Configurable tag syntax.</li>
<li>The if elseif constructs are passed to the PHP parser, so the if expression syntax can be as simple or as complex an evaluation as you like.</li>
<li>Allows unlimited nesting of sections, if&#8217;s etc.</li>
<li>It is possible to embed PHP code right in your template files, although this may not be needed (nor recommended) since the engine is so customizable.</li>
<li>Built-in caching support. (wow. No more low resources server burden).</li>
<li>Arbitrary template sources.</li>
<li>Custom cache handling functions.</li>
<li>Plugin architecture.</li>
<li>Re usability of code.</li>
</ul>
<p>Smarty requires a web server running PHP 4.0.6 or greater. </p>
<h5>Required Smarty library files (all in lib folder)</h5>
<p><strong>libs/</strong><br />
Smarty.class.php<br />
Smarty_Compiler.class.php<br />
Config_File.class.php<br />
debug.tpl<br />
internals/*.php (all of them)<br />
plugins/*.php (all of them)</p>
<h5>Smarty Website Structure</h5>
<p>Following folders are essential in a smarty based website. templates has tpl files and templates_c stores cached pages (It is website cache). Smarty contains lib folder containing smarty software. Name of these default folders can be changed and it is recommended to change these and tell script accordingly templates directory and cache directory and location of Smarty.class.php.</p>
<p><strong>templates_c<br />
templates<br />
Smarty<br />
</strong></p>
<p>Images and css folders you will have to create, as every website has these. With these you can create a configs folder to store configuration files.</p>
<p><strong>images<br />
css<br />
configs<br />
</strong></p>
<p>Here&#8217;s how you create an instance of Smarty in your PHP scripts:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Smarty.class.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$smarty</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Smarty<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h5>How Smarty Works</h5>
<p>After you have created above mentioned structure, the concept is to create PHP pages and place those in root and in templates folder create tpl files for these pages. There will be index.php file containing PHP code and variables at root directory of website and there will be index.tpl file in templates folder containing html code, design part of website and smarty code. We send PHP variables from index.php to index.tpl smarty code and then it mix things together in simple words and compile the page for you and build its cache too.</p>
<h5>Sample index.php Code</h5>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">require</span> <span style="color: #0000ff;">'Smarty/libs/Smarty.class.php'</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// $smarty-&gt;caching = false;</span>
<span style="color: #000088;">$smarty</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Smarty<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$smarty</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">display</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'index.tpl'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>OR</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// error_reporting(E_ALL ^ E_NOTICE);</span>
<span style="color: #666666; font-style: italic;">// display errors</span>
<span style="color: #666666; font-style: italic;">// @ini_set(&quot;display_errors&quot;, &quot;1&quot;);</span>
<span style="color: #b1b100;">require</span> <span style="color: #0000ff;">'Smarty/libs/Smarty.class.php'</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// $smarty-&gt;caching = false;</span>
<span style="color: #000088;">$smarty</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Smarty<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$smarty</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">assign</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;HOME&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;class='selected'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$smarty</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">display</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'index.tpl'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Above we are sending variable from PHP to smarty for navigational element HOME. In tpl file we will write some smarty code which will apply class selected to that element.</p>
<h5>Sample index.tpl Code</h5>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">{include file=&quot;header.tpl&quot; title=&quot;header&quot;}
{include file=&quot;body.tpl&quot; title=&quot;body&quot;}
{include file=&quot;footer.tpl&quot; title=&quot;footer&quot;}</pre></div></div>

<p>Above we included header, body and footer code in single index page.</p>
<p>Download smarty based website. Just upload it at your PHP enabled server or copy files to WAMP local server and browse index.php to see smarty in action.</p>
<p><span class="downloadfile"><a href='http://www.webstylepress.com/wp-content/uploads/2008/10/smarty-example.rar'>Download Smarty Example</a></span></p>
<p><a href="http://www.webstylepress.com/smarty-for-smart-developers/">Smarty For Smart Developers</a> is a post from: <a href="http://www.webstylepress.com">Web Style Press, Best Practices from all the Web, Build Better Websites</a></p>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li><a href="http://www.webstylepress.com/javascript-essentials-part-3/" title="Javascript Essentials Part 3">Javascript Essentials Part 3</a></li><li><a href="http://www.webstylepress.com/traffic-widgets-website-banned-google/" title="Traffic Widgets Can Get your Website Banned">Traffic Widgets Can Get your Website Banned</a></li><li><a href="http://www.webstylepress.com/simple-rollover-swap-image/" title="Simple RollOver Swap Image">Simple RollOver Swap Image</a></li><li><a href="http://www.webstylepress.com/swap-depth-in-flash/" title="Swap Depth In Flash">Swap Depth In Flash</a></li><li><a href="http://www.webstylepress.com/flash-resources-and-tutorials/" title="Flash Resources and Tutorials">Flash Resources and Tutorials</a></li><li><a href="http://www.webstylepress.com/html-quick-reference/" title="HTML Quick Reference &#8211; Complete Guide">HTML Quick Reference &#8211; Complete Guide</a></li><li><a href="http://www.webstylepress.com/jcarousel-lite-scroll/" title="jCarousel Lite Scroll &#8211; Fancy Scroll">jCarousel Lite Scroll &#8211; Fancy Scroll</a></li><li><a href="http://www.webstylepress.com/force-file-download-do-not-display-open-in-browser/" title="Force File download &#8211; Do Not Display Open In Browser">Force File download &#8211; Do Not Display Open In Browser</a></li><li><a href="http://www.webstylepress.com/how-to-control-font-size-in-percentage/" title="How to Control Font Size in Percentage">How to Control Font Size in Percentage</a></li><li><a href="http://www.webstylepress.com/lorem-ipsum-ready/" title="Lorem ipsum Ready to Use">Lorem ipsum Ready to Use</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.webstylepress.com/smarty-for-smart-developers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

