I’m not a big fan of CMS Made Simple, but I end up doing a lot of sites in it by request. It’s taken me awhile, but I think I’ve found a way to structure templates that doesn’t make me want to club baby seals out of frustration.
First, what I don’t like about it. There are a lot of reasons, but these are the major ones:
- Templates and stylesheets are stored in the database and edited through a textarea in the browser. This is the biggest frustration I have.
- The textarea is only 685px wide, so lines frequently wrap, reducing the readability. I use Chrome, so I can resize the textarea on the fly, but it reverts back to the default every time I reload the page.
- That’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.
- There’s also no syntax highlighting, which greatly reduces the readability.
- 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.
- The documentation leaves a lot to be desired. To be fair, some of my frustration can be attributed to the fact that I don’t really sit down and RTFM enough, but I can’t tell you how many hours I’ve spent reading and searching for answers to things that I would have knocked out in 5 minutes in WordPress. There doesn’t seem to be any comprehensive explanations of how the system is designed and how you should interact with it.
- It uses Smarty. I like MVC, and I’m warming up to Smarty, so I guess my real problem isn’t with Smarty itself, but with how CMSMS integrates with it. I hadn’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.
So, I’ve basically just bypassed CMSMS’s architecture as much as possible and done things the traditional way. Here’s how you can write a CMSMS template using a real text-editor and an FTP client.
- 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.
- Write all the templates (overall layout, page, module-specific, etc) in .tpl files using Smarty. It’s actually not that bad once you don’t have to deal with all of the other problems.
- Then write a PHP class with all the methods you’ll need to pull and push data. Assign variables to Smarty so you can use them in your .tpl files.
- Create a User Defined Tag (named ‘example_header’ here) to include your class and template header
-
global $gCms, $smarty; require_once($gCms->config['root_path'] .'\uploads\2009-example\example2009.php'); $smarty->assign('example2009', new example2009); $smarty->display($gCms->config['root_path'] .'\uploads\2009-example\header.tpl');
-
- You’ll still define a template in CMSMS, but instead of writing the markup/logic there, you’ll just call the external .tpl files. There’s a bug where the admin page content box won’t be displayed if you don’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.
-
{example_header} {content|substr:0:0} {include file="$exampleDir\\home-page.tpl"} {include file="$exampleDir\\footer.tpl"}
-
- The class constructor can assign to Smarty any variables you’ll want throughout the templates, like the location of the template directory
-
$smarty->assign('exampleDir', $gCms->config['root_path'] .'\uploads\2009-example');
- Module-specific templates just need to include the .tpl files
-
{include file="$exampleDir\\calendar-header.tpl"} {include file="$exampleDir\\calendar-month.tpl"}
-
It seems to be enough (at least using 1.7.0) to have a content tag inside a smarty comment to get the content box to display in the admin page (item 3):
{*
{content}
*}
This will have the same effect but perhaps save a few cycles of processing.
CMSMS now has support for EditArea, a color coding text editor that loads in a textarea like other javascript WYSIWYG editors. Still, it is a bit of a pain to have those things saved in the db when you want to synchronize a few sites.
You need the Template Externalizer module. When you turn it on, it copies the database templates and stylesheets to flat files so you can use any editor you want. When you’re done, you turn it off and it copies all that back to the database.
I agree about the documentation, I struggled along using that stupid textarea for some time before I found the Externalizer modulke.
Even today… I can remember reading something about CMSMS, and can’t remember if it was in the Wiki, or the forums, or in the API, or on of the developer’s websites… IME, you pretty much have to Google for everything…
After reading your first paragraph I knew I was at the right place. Lately I’ve been feeling for clubbing everything around me thanks to the wonderful CMSms logics
Very helpful, an alternative
Add ‘plugins/function.get_tpl.php’:
GetConfig();
$smarty->display($config[‘root_path’] . ‘\uploads\\’ . $params[‘path’]);
}
?>
Use:
{get_tpl path=”sections\\SectionFormProduct.tpl”}