Tips For Inserting Code Into CMS Made Simple Pages

Written by webchicklet on April 11, 2008 – 2:01 pm -

The following tips apply specifically to CMS Made Simple, but some may also apply to any CMS that relies on Smarty as its backend template engine. (Smarty is used in quite a few CMS products).

You’ve been told that CMS Made Simple is … well … simple. And it is … up to a point. There are exceptions to every rule, of course, and CMS Made Simple is no exception to that rule. :)

If you plan to create a simple web site, with nothing more than text and graphics, you probably won’t find a much easier to user CMS than CMS Made Simple. But if you want to get a little fancier than that, you’ll need to put on someone’s geek hat and at least have a rudimentary amount of coding knowledge. You don’t have to have much, mind you, but you should at least be able to understand what an HTML tag is. If you’ve ever played around a little with HTML or CSS or PHP, you’re good to go.

So here are a few tips for those times when you want to include more than just text or graphics on one of your CMS Made Simple web pages.

I need to include some PHP code in my web page. How do I do that?

CMS Made Simple allows you to create your own tags that you can use over and over again if you want. These tags are called User Defined Tags (UDTs) because you create them. If you want to insert some PHP code on your page (to make that page do something extra spiffy), all you have to do is insert the PHP code into a UDT and place the UDT tag wherever you want it in your page.

Here are the more detailed steps to doing this.

  • In admin, go to Extensions / User-defined Tags, and click on Add User Defined Tag.
  • Now type a name for your new tag in the Name box. Keep it short and make sure it only contains letters, numbers, and underscores.
  • Now paste the php code into the Code box (leaving the start and end PHP tags out - meaning don’t include “” at the beginning and end of your PHP code), and click Submit.
  • Now place your newly-named tag in your page like this: {mytagname} where mytagname is whatever you named your new tag.

I need to include some Javascript code (or a link to an external javascript) in my web page. How do I do that?

So you’ve found a really cool widget that you want to run on your web page, but it’s a javascript and every time you try to put that javascript in the page editor, it bombs out. Why, oh why, does it do that? Actually, there’s a good reason for it. You see, CMS Made Simple (as well as a lot of other CMS’s) uses a template engine called Smarty. Smarty allows you to use design templates into which you place special tags that tells Smarty where to insert stuff (like your menu, your content, your footer copyright, etc.). These special tags begin and end with curly braces { }. When Smarty sees something within curly braces, it thinks it’s a special tag and tries to do something with it. Unfortunately, Javascript also uses curly braces, so Smarty gets confused and tries to interpret whatever is inside those curly braces, and the whole thing just bombs out.

But don’t worry, there is a way around the problem. Smarty (and therefore, CMS Made Simple) anticipated this problem, and gave us a special Smarty tag to handle it. It’s the {literal} {/literal} set of tags. Anything you put inside the {literal} {/literal} set of tags will not be process by Smarty at all. Smarty will ignore everything within the {literal} {/literal} tags, so it won’t get confused by any curly braces within your Javascript. The Javascript, however, will be processed by the user’s browser, even though it isn’t processed by Smarty - and that’s exactly what you want to have happen.


I need to include some CSS styles directly in my web page, rather than in my template’s stylesheet. How do I do that?

Sometimes, you want to use an existing page template, but just add a little bit of extra styling to it for just one page. Instead of creating a whole new page template just for that one little change, you can just insert the extra CSS style code into the body of this page only. Essentially, this the same situation as the Javascript question above. Because CSS uses curly braces within its code, you need to place all the CSS code within {literal} {/literal} tags. This way, Smarty will ignore the code, but the user’s browser will process it. Again, that’s exactly what you want to have happen.


Ok, so now we know that to insert PHP code into our pages, we create a User Defined Tag. We also know that to include javascript or CSS code, we wrap the code in {literal} {/literal} tags. Great! Wait, there’s one more thing you might want to consider.

What if you want to easily re-use that javascript or CSS code on other pages? Don’t place it in a UDT because that’s only for PHP code. You can, however, place it (along with the {literal} {/literal} tags) within a Global Content Block.

In the admin, under Content, you’ll see a submenu called Global Content Blocks. It essentially works just like the User Defined Tags, except that it lets you place non-PHP code there (HTML, javascript, etc). Add one of these blocks, name it something, place your javascript within {literal} {/literal} tags into it, and save it. Voila! Now you can easily reuse this content block anywhere you want simply by placing this tag in your page: {global_content name=’whateveryounamedit’}


And those are a few tips to help you add code into your CMS Made Simple pages. Now go have fun.

Share and Enjoy:
  • TwitThis
  • StumbleUpon
  • description
  • del.icio.us
  • Google
  • YahooMyWeb
  • Sphinn
  • Mixx
  • Facebook
  • Propeller
  • Digg
  • Reddit
  • Blogsvine

Tags: , , , , , ,
Posted in CMS Made Simple |

Leave a Comment

RSS