<?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>workblog &#187; Smarty</title>
	<atom:link href="http://iandunn.name/workblog/category/smarty/feed/" rel="self" type="application/rss+xml" />
	<link>http://iandunn.name/workblog</link>
	<description></description>
	<lastBuildDate>Wed, 25 Aug 2010 22:23:41 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to Build a Template in CMS Made Simple While Maintaining Sanity</title>
		<link>http://iandunn.name/workblog/how-to-build-a-template-in-cms-made-simple-while-maintaining-sanity/</link>
		<comments>http://iandunn.name/workblog/how-to-build-a-template-in-cms-made-simple-while-maintaining-sanity/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 14:56:39 +0000</pubDate>
		<dc:creator>Ian</dc:creator>
				<category><![CDATA[CMS Made Simple]]></category>
		<category><![CDATA[Smarty]]></category>

		<guid isPermaLink="false">http://iandunn.name/workblog/?p=133</guid>
		<description><![CDATA[I&#8217;m not a big fan of CMS Made Simple, but I end up doing a lot of sites in it by request. It&#8217;s taken me awhile, but I think I&#8217;ve found a way to structure templates that doesn&#8217;t make me want to club baby seals out of frustration.
First, what I don&#8217;t like about it. There [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m not a big fan of <a href="http://www.cmsmadesimple.org/">CMS Made Simple</a>, but I end up doing a lot of sites in it by request. It&#8217;s taken me awhile, but I think I&#8217;ve found a way to structure templates that doesn&#8217;t make me want to club baby seals out of frustration.</p>
<p>First, what I don&#8217;t like about it. There are a lot of reasons, but these are the major ones:</p>
<ul>
<li>Templates and stylesheets are stored in the database and edited through a textarea in the browser. This is the biggest frustration I have.
<ul>
<li> The textarea is only 685px wide, so lines frequently wrap, reducing the readability. I use <a href="http://google.com/chrome">Chrome</a>, so I can resize the textarea on the fly, but it reverts back to the default every time I reload the page.</li>
<li>That&#8217;s another thing, I have to reload the page every time I want to save, rather than just CTRL-S in my text editor, which my FTP client automatically detects and re-uploads the page.</li>
<li>There&#8217;s also no syntax highlighting, which greatly reduces the readability.</li>
<li>I want to use a real, full-screen text editor with all of the normal features that programmers use, not a crappy little textarea where everything is squished together and looks the same, and where it takes 3 seconds rather than .25 to save changes.</li>
</ul>
</li>
<li>The documentation leaves a lot to be desired. To be fair, some of my frustration can be attributed to the fact that I don&#8217;t really sit down and RTFM enough, but I can&#8217;t tell you how many hours I&#8217;ve spent reading and searching for answers to things that I would have knocked out in 5 minutes in Wordpress. There doesn&#8217;t seem to be any comprehensive explanations of how the system is designed and how you should interact with it.</li>
<li>It uses <a href="http://smarty.net">Smarty</a>. I like MVC, and I&#8217;m warming up to Smarty, so I guess my real problem isn&#8217;t with Smarty itself, but with how CMSMS integrates with it. I hadn&#8217;t worked with Smarty before, so lacking any in-depth documentation from CMSMS, it took me a long time to figure out exactly where it fits into the architecture and how to do non-trivial things in it.</li>
</ul>
<p>So, I&#8217;ve basically just bypassed CMSMS&#8217;s architecture as much as possible and done things the traditional way. Here&#8217;s how you can write a CMSMS template using a real text-editor and an FTP client.</p>
<ol>
<li>Store all your templates, stylesheets and code in a directory in /uploads/. We can then just include everything from CMSMS, instead of having to write them inside CMSMS.
<ul>
<li>Write all the templates (overall layout, page, module-specific, etc) in .tpl files using Smarty. It&#8217;s actually not that bad once you don&#8217;t have to deal with all of the other problems.</li>
<li>Then write a PHP class with all the methods you&#8217;ll need to pull and push data. Assign variables to Smarty so you can use them in your .tpl files.</li>
</ul>
</li>
<li>Create a User Defined Tag (named &#8216;example_header&#8217; here) to include your class and template header
<ul>
<li>
<pre name="code" class="php">
global $gCms, $smarty;
require_once($gCms-&gt;config[&#039;root_path&#039;] .&#039;\uploads\2009-example\example2009.php&#039;);
$smarty-&gt;assign(&#039;example2009&#039;, new example2009);
$smarty-&gt;display($gCms-&gt;config[&#039;root_path&#039;] .&#039;\uploads\2009-example\header.tpl&#039;);
</pre>
</li>
</ul>
</li>
<li>You&#8217;ll still define a template in CMSMS, but instead of writing the markup/logic there, you&#8217;ll just call the external .tpl files. There&#8217;s a bug where the admin page content box won&#8217;t be displayed if you don&#8217;t call content in the internal template, so we call it, but run it through a modifier to make it empty. Then we can call it whenever and however we want to later on in the external file.
<ul>
<li>
<pre name="code" class="php">

{example_header}
{content|substr:0:0}
{include file=&quot;$exampleDir\\home-page.tpl&quot;}
{include file=&quot;$exampleDir\\footer.tpl&quot;}
</pre>
</li>
</ul>
</li>
<li>The class constructor can assign to Smarty any variables you&#8217;ll want throughout the templates, like the location of the template directory</li>
<li>
<pre name="code" class="php">
$smarty-&gt;assign(&#039;exampleDir&#039;, $gCms-&gt;config[&#039;root_path&#039;] .&#039;\uploads\2009-example&#039;);
</pre>
</li>
<li>Module-specific templates just need to include the .tpl files
<ul>
<li>
<pre name="code" class="php">
{include file=&quot;$exampleDir\\calendar-header.tpl&quot;}
{include file=&quot;$exampleDir\\calendar-month.tpl&quot;}
</pre>
</li>
</ul>
</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://iandunn.name/workblog/how-to-build-a-template-in-cms-made-simple-while-maintaining-sanity/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
