Smarty. MT. Dynamic

Smarty Docs

Now that Smarty is built into MT, you've got a whole load of new features that you can use. Just have a look at the documentation everything discussed in those docs are available to MT users, the only difference is instead of single braces you need to use double, for example where in the Smarty docs it gives you a line like this

{include file="sidebar.php"}

when you implement that into MT it will need to become

{{include file="sidebar.php"}}

This was chosen over the single braces because the single braces can cause problems when you start writing Javascript. None-the-less if you really wish to use single braces, find in your mtview.php template the following line (thanks Brad for the code):

$mt = new MT(<$MTBlogID$>, '<$MTCGIServerPath$>/mt.cfg');

and add after it:

$ctx =& $mt->context(); $ctx->left_delimiter = '{'; $ctx->right_delimiter = '}';

Be warned, this is not recommended. If you decide to change it to one brace then you will need to use delimiters to escape pieces of your code like javascript etc. Again this is not recommended, having the default double brace will not require you to use the delimiters.

These smarty tags can be used in any dynamic template and can only be used in dynamic templates. These tags cannot be used whilst specifying where your archives permalinks (under Weblog Config → Archiving → Archive File Templates)

Smarty Plugins

One can also use the heaps of Smarty Plugins that can be found in the wiki. There are many plugins there, all you need to do is copy over the code into a new file - the name is specified in the code of the plugin. Then you can call it in your dynamic templates. For example this URLPlugin, I copied the source code into a file called function.url.php and then was able to use it. The file would be located

MT_DIR/php/plugins

If the directory isn't already there, create it ! Smarty Plugins can be grouped as follows:

  • Blocks: A block function is basically just a container tag.
  • Functions: Functions create tags you can use in templates.
  • Modifiers: These are your text filters
  • Output Filters: These plugins manipulate the output produced by your site
  • Post Filters: These plugins manipulate the contents of your posts

One must remember that these plugins are written in PHP so are only available to templates that are built dynamically. Current MT plugins that have no been converted to PHP will not work with dynamic templating for the simple reason that they are written in Perl while the dynamic templating is written in PHP and Perl != PHP. If you miss some of your plugins, try contacting the author. Most likely you will find they will be converting their plugins using the PHP Api

Cleaner URLs

Another tip for dynamic templating users, previously when specifiying archive permalinks (under Weblog Config → Archiving → Archive File Templates) you would need to specify a physical file like so:

<$MTCategoryLabel dirify="1"$>/index.html

This is no longer necessary with the dynamic engine. If you have dynamic building enabled for archive templates, you can now set your permalinks for archives to be similar to

<$MTCategoryLabel dirify="1"$>/

and so much cleaner.

You will also see a new template called Dynamic Pages Error Template This template is for you to define the error pages that mtview.php creates. The main tag in that template is

<$MTErrorMessage$>

PHP Markdown

With MT 3.1 comes the plugin pack, and in the plugin pack comes Markdown. Unfortunately in its current perl state, Markdown will only work with static pages. For dynamic pages see PHP Markdown To install it with MT, download the zip, extract the markdown.php file. Upload that file to

MT_DIR/php/plugins

If the directory isn't already there, create it !

Then follow the instructions on the PHP Markdown page under Smarty:

If your program use the Smarty template engine, PHP Markdown can now be used as a modifier for your templates. Rename markdown.php to modifier.markdown.php and put it in your smarty plugins folder.

Leave a comment

Preview