Tweaking Movable Type Part II
Oct 20th, 2005 by Karen
I said that I would get back to everyone about how set up linked templates as the defaults in Movable Type. I did some investigating and found out its possible. However, I will say in advance of my explanation that you might want to polish your Perl readings skills and Unix permissions skills a bit. This tweak requires you edit several Perl files on the Movable Type server. It isn’t difficult but you should be aware that it isn’t “a snap”.
When I last posted on this topic, I said that it was possible to have a set of templates be installed in every new blog that was created in Movable Type. This post discusses at length not only how to have the same templates installed by default but how to keep the template consistant across the blogs, after the blog has been created. The key to this is using “linked templates”. When you got and look at your templates in Movable Type you will say a box that says “linked template” that allows you to put in the path to a file which is used as the template. The beauty of this is once you make this link you can use the Movable Type interface to update the template in one blog and it will update everywhere that linked template is being used. However, there is a catch or two.
First, the file you want to be the template needs to have its permissions set so that the user that runs your web server has read and write permissions. Otherwise there is no way for Movable Type to update this file. Second, you need to know where the file you want to use as a template lives. I highly reccomend you use an absolute path here. The reason is if you use a relative path you will have to change it as you create new blogs because the relative path is from the directory where blog is located. Third, you need to tell Movable Type that when a new blog is created that you want to use linked templates for your template files. This means editing the default-templates.pl which lives in where_your_MT_was_installed/lib/MT . You have to do this if you want to add modules by default to every new weblog. However, when you want to use linked templates you have to take this one step further.
So find the place in the default-templates.pl file that says
my $templates = [
{
'outfile' => 'index.html',
'name' => 'Main Index',
'type' => 'index',
},
You want to change this to say
The code in the file looks like this
my $templates = [
{
'outfile' => 'index.html',
'name' => 'Main Index',
'type' => 'index',
'linked_file' => 'path to your linked template' - This will look something like /directory/directory/filename.tmpl
},
You will need to add this line for all the files that you want to make linked templates. This includes all the nice modules that you've just created for yourself! Which means that the module code that I demoed in the first Tweaking Movable Type post needs to be changed to
{ 'type' => 'custom',
'name' => 'Banner Module',
'linked_file' => '/somepath/banner_module.tmpl'
},
{ 'type' => 'custom',
'name' => 'Sidebar Module',
'linked_file' => '/somepath/sidebar_module.tmpl'
},
];
As far as which files to make linked templates, I would advise that you do this will all the files you plan to change in any way. It will help you keep everything in sync.
Another things you should consider doing my default is making all of your pages dynamic. This will save you the trouble of rebuilding HTML files and keep the number of files on the server to a minimum. If you have already created a blog then you can do this by going into the “Publishing Defaults” under the blogs “Settings” and set the Dynamic Publishing to Set each template’s Build Options separately. This will allow you to go into each template and check the “Enable dynamic building for this template” box. If this seems like a pain and you want to just have all your templates be dynamic by default then there is a cheat.
Got to the Blog.pm file which is located in where_your_MT_was_installed/lib/MT . The file has a section called sub set_defaults that looks like this
sub set_defaults {
my $blog = shift;
require MT::ConfigMgr;
$blog->days_on_index(7);
$blog->entries_on_index(0);
$blog->words_in_excerpt(40);
$blog->sort_order_posts('descend');
$blog->language(MT::ConfigMgr->instance->DefaultLanguage);
$blog->sort_order_comments('ascend');
$blog->file_extension('html');
$blog->convert_paras(1);
$blog->allow_unreg_comments(1);
$blog->allow_reg_comments(1);
$blog->allow_pings(1);
$blog->moderate_unreg_comments(MT::Blog::MODERATE_UNTRSTD());
$blog->moderate_pings(1);
$blog->require_comment_emails(1);
$blog->allow_comments_default(1);
$blog->allow_comment_html(1);
$blog->autolink_urls(1);
$blog->allow_pings_default(1);
$blog->require_comment_emails(0);
$blog->convert_paras_comments(1);
$blog->email_new_pings(1);
$blog->email_new_comments(1);
$blog->sanitize_spec(0);
$blog->ping_weblogs(0);
$blog->ping_blogs(0);
$blog->ping_technorati(0);
$blog->archive_type('Individual,Monthly,Category');
$blog->archive_type_preferred('Individual');
$blog->status_default(1);
$blog->junk_score_threshold(0);
$blog->junk_folder_expiry(60); # 60 days
$blog->custom_dynamic_templates('none');
$blog->internal_autodiscovery(0);
$blog->basename_limit(30);
# $blog->server_offset(0);
$blog->children_modified_on('20101231120000'); # something far in the future to force dynamic side to read it.
$blog;
}
Find the line:
$blog->custom_dynamic_templates('none');
and change it to
$blog->custom_dynamic_templates('custom');
This will make the change in the Publishing tab of Settings automatically.
You will also want your templates to be dynamic when you create a new blog. This is done by editing the default_templates.pl file that I keep mentioning. Below is what the entry for the “Main Index” page would look like. Modules don’t have a “dynamic” form so you don’t have to put any additional code in this file for them.
'name' => 'Main Index',
'type' => 'index',
'linked_file' => '/somepath/main_index.tmpl',
'build_dynamic' => '1'
You now have linked templates that allow your weblogs to be dynamically updated by default! One very important note I should mention is that before you make any of these changes you need to make a back up your original files. That way if you make a mistake your instance of Movable Type will not be irreversablly destroyed. All you have to do if copy your backup file over the file you changed and things will work again.

