May 27, 2005

Troubleshooting Smarty Errors

This tutorial is written by LMT guest author Arvind Satyanarayan of Movalog.
Tutorial cross posted on Movalog and Learning Movable Type

If you move from static publishing to dynamic publishing in Movable Type, you may encounter a variety of confusing error messages in Smarty, the system MT uses to create its dynamic pages. This tutorial will explore several of the errors you may experience, explain what they mean, and show you how to solve them. This is by no means a complete guide to every error you may experience; I will continue to add to this tutorial as I come by more of them.

The Basics

Many of the error messages you may see will take the format:

Smarty Error: [in mt:## line:##]

This error message provides useful information that can help you troubleshoot the problem. The first numbers after mt: give the template_id of the template that contains the error. Using this template ID, you can tweak the address of mt.cgi to take you to the Edit Template page for the template in question. (See the example a few paragraphs down.)

The next part of the error message narrows down the error even further by telling you the specific line on which the error has occurred. I use a text editor called UltraEdit to edit my templates which provides line numbers. Line numbers aren't available within the MT UI but you can copy the code to a text editor that has line numbering capabilities.

For example, if this were the start of an error message:

Smarty Error: [in mt:16 line:200]

you would point your browser to http://path/to/mt.cgi?__mode=view&_type=template&id=16&blog_id=1 where 16 is the template ID and 1 is the blog_id for the blog (you can find this out by navigating to your blog's main menu and looking at the address bar). You could then copy the template body into a text editor with line numbering capabilities to find line 200 and the location of the error.

Error Messages

Directory Not Found


Smarty error: the $compile_dir '/home/blahblah/www/blog/templates_c' does not exist, or is not a directory.

You must create a directory called templates_c and assign it with permissions of 777. Your templates will be compiled in this directory. If you have added directives in mtview.php to cache the templates, you may get a similar message but telling you the cache directory hasn't been created. To resolve this error, you will need to create a directory called cache with permissions of 777.

Unrecognized Tag


Smarty error: [in mt:16 line 21]: syntax error: unrecognized tag 'MTEntryProtect' (Smarty_Compiler.class.php, line 556)

This is one of the most common error messages experienced while moving to the dynamic system, especially if you have a heavily customized template.

These errors occur because the dynamic system is written in PHP and tags (whether they are provided by MT or by a plugin) must be ported to PHP before they will work in the dynamic system. Plugins must contain PHP files for the tags or else you cannot use them with MT's dynamic system.

To resolve this error, you can do one of two things. You can put the template code, where applicable, into a separate index template, publish that template statically, and then include the code snippet template's output file into your original template using the following bit of Smarty code

{{include "/path/to/static.php"}}

Or, if you cannot put the tag into a separate file, you will have to remove the tag or find a PHP port of the tag to use in your template.

Modifier Errors


Smarty error: [plugin] modifier 'markdown' is not implemented (core.load_plugins.php, line 118)

Global (or text) filters are called "Modifiers" in Smarty language. This error is similar to the unrecognized tag in that Smarty is unable to find a PHP port of the modifier. All filters must also have a PHP port if they are to work with the dynamic templating. You can find PHP ports of Markdown, Smartypants and Textile here. If you are unable to find a PHP port for your filter, the only resolution is to either remove the syntaxing the modifier provides (for example with Smartypants you'll need to remove smartypants="1") or select another filter that does have PHP port.

Unclosed Tag

For example

Smarty error: [in mt:285 line 1]: syntax error: unclosed tag {MTComments} (opened line 1). (Smarty_Compiler.class.php, line 308)

This is quite an easy error to understand. Basically you've forgotten to close a container tag. With the above example, I've forgotten the </MTComments> tag. The error message even tells you where you opened the container tag!

Mismatched Tag

For example

Smarty error: [in mt:285 line 3]: syntax error: mismatched tag {/MTComments}. expected {/MTCommentEntry} (opened line 2). (Smarty_Compiler.class.php, line 2211)

This error simply means that you've prematurely closed one of the container tags forgetting to close one that was underneath it. With the above example, this is the code that caused it


As can be seen, I forgot to close the MTCommentEntry container tag. Again the error message is helpful and gives you the line where the unclosed container tag is.

Unprocessed PHP

If you are using PHP in your templates and suddenly find that the PHP code isn't being parsed, make sure that you are using the full PHP tags, i.e.

<?php ... ?>

as opposed to

<? ... ?>

Also, you cannot use normal MT Tags within blocks of PHP code. If you wish to use MT Tags within blocks of PHP, you must call their PHP counterpart. For example, if I wanted to use <MTEntryBody> within PHP code, I would need to use this instead.


PHP Errors

You may also come across a variety of PHP errors that are horribly unhelpful. I would recommend you read Making Sense of PHP Errors to help you understand what the errors mean and how to resolve them.

Other Tips

I use a lot of PHP in my templates and often I find it easier to troubleshoot errors by viewing the template after Smarty has finished generating the template. This is when I use the files in the templates_c directory. This directory contains the templates that Smarty has compiled. The file names can be difficult to decipher but the important part is the ending of the file name. It will look something like this


followed a number and then the extension (.php). The number is the id of the template. Therefore if I wanted to see the output of template whose id is 14, I would open the file that ended


I wouldn't recommend you tweak things directly here however. If you were to make a mistake you could potentially delete the file and within MT initiate a rebuild of all files.

Further Reading:

  • Dynamic Publishing: PHP Architecture Overview - Useful information on how the dynamic system works.

  • PHP Dynamic Publishing: Developing Plugins - Information on how to develope plugins for the PHP system

  • How to Speed Up Publishing in Movable Type - Useful tips on migrating to the dynamic templating.

Has this tutorial been helpful? Please consider linking to Learning Movable Type at . Thanks!

Posted by Arvind Satyanarayan on May 27, 2005 to Dynamic Publishing
Comments(2) | Email to a friend | Printer-friendly version


If you would like to send a trackback
please use the following URL:

» Migrating to MT Dynamic Publishing from Warnadunia.NET
I am working on the dynamic publishing for this weblog. You will experience broken links, pages not loeaded correctly. First thing I learn: always backup your template/template file before changing the setting into dynamic; or you will have Jupiter fal......[read more]

Tracked: June 2, 2005 03:36 PM


Elise, I'm dealing with an unrecognized tag issue with MTFilterCategories. Thanks to your post, I now know the nature of the problem. On the weblog in question, I've shifted to static publishing and the plug works okay...but I'd like to be able to go back to dynamic publishing at some point.

Could you possibly expand on your suggestion about putting the tag in a separate file? I'm not quite following you. Not your fault; I'm just slow.

Hi Waveflux,

I'm not entirely sure how you're using the MTFilterCategories plugin to give you specific help but what you'll need to do is create a new index template and move the FilterCategories code into it. Rebuild the template and then include it in using a PHP include like so

<?php include("/path/to/file"); ?>

Post a comment

(Before posting a comment please see the Comments and Trackbacks Policy. Do you need help troubleshooting your weblog? Please post questions and requests for support at the MT Support Forums. Thanks!)

Remember Me?

(you may use HTML tags for style)

Email to a friend

Email this article to:

Your email address:

Message (optional):