« What is a Cool IRI? | Main | Full Featured FCKeditor on Movable Type »

Tool for adding new default templates

Go to Korean entry.


What is a default template in Movable Type ?

Default templates are those which are automatically created by creating new blog.
And by virtue of MT 3.2's TemplateRefresh plugin, default templates can be restored in existing blogs.

In some cases, we may want to provide MT with our own default templates. By doing this, we can reduce additional routine processes. MT's TemplateRefresh can't do this, because this plugin only works for predefined default templates.

If you want to make a template as default in MT, first you have to locate that under (mt home)/default_templates/ folder. Next, you have to add some required informations into (mt home)/lib/MT/default-templates.pl by your hands. Lastly, for complete measures, you have to add template's digest information into TemplateRefresh.pl plugin file. These steps for making templates to be default are routinary. So I develped this tool.

This "Add Default Templates" is a tool that can add your default template to MT system and TemplateRefresh plugin. It can also delete your default template from those.

Requirement

  • Movable Type 3.2

Installation

Download this plugin and untar it under (mt home) folder like $ tar xvfz addDefaultTemplates.tar.gz. Then the files will be located as below:

  • (mt home)/tools/add-default-templates
  • (mt home)/tools/default_templates/test.tmpl.add
  • (mt home)/plugins/alogblog/addDefaultTemplates.pl
  • (mt home)/plugins/TemplateRefresh/TemplateRefresh.pl

How to Use

Preparing your own default template

In (mt home)/tools/default_templates/ folder, there is one example template file. You can use it as a model for template file.

For example, you want a default index template which is a simple CSS as like,

To do that, you have to prepare any_file_name.tmpl.add file under (mt home)/tools/default_templates/ folder. "any_file_name" can be anything. In this case, let's assume it as mytest.tmpl.add. Its content may be as follows.

$/ = undef;
my $template = {
        'outfile'       => 'test.css',
        'name'          => 'My Test CSS',
        'type'          => 'index',
        'rebuild_me'    => '1',
        'text'          => <DATA>
};
$template;
__DATA__
.test
{
        font-family: Arial, Verdana, Sans-Serif;
        font-size: 12px;
        padding: 5px 5px 5px 5px;
        margin: 0px;
        background: #fff url(<MTBlogName dirify="1">.gif);
}
Updating default templates in MT system and TemplateRefresh plugin

Under (mt home)/ folder, run the command, $ perl   tools/add-default-templates. Then all your own default templates, (mt home)/tools/default_templates/*.tmpl.add, are updated to MT system and TemplateRefresh plugin.

If you want to delete some your own default template from MT system and TR plugin, first you have to rename AAA.tmpl.add to AAA.tmpl.del, and then run the same command as above.

Updating default templates in existing blogs

Go to System Overview menu's Weblogs page. Select blogs you want to update. And then do "Add Default Template(s)" action. This action will add only omitted default templates to selected blogs.

Notes

  • Body contents of template should be located under __DATA__ in *.tmpl.add file.
  • 'type' can be 'index', 'category', 'archive', 'individual', or 'custom'.
  • 'archive' type is Date-based archive.
  • 'custom' type is Module in terms of MT template menu.
  • 'rebuild_me' can be '0' or '1' which mean false/true for each.
  • I provide you with updated TemplateRefresh.pl file. It is originally from Movable Type as you know. Origianl TR 1.0's plugin action is not suitable in adding omitted default templates. After adding your default templates into MT, you can do "Refresh Template(s)" action in List Weblogs of System Overview. But this action inadvertently refreshes all default templates which have been altered. In many case, every possible default templates are customized. So in case that we want to only add omitted(or deleted) default templates while other altered/customized default templates are unrefreshed, original TR can't do it. Therefore I added a "Add Default Template(s)" action to 1.0 TR plugin. This action does adding omitted default templates into current blog while other existing but modified default templates are intact. I want 6A to include this action in next TR version. If then, I will remove this file from my compressed file.

License

TemplateRefresh.pl follows sixapart's copyright.

Relased under the Creative Commons License.

Version History

  • 3.2.01 : newly created MT tool

TrackBack

TrackBack URL: http://alogblog.com/movabletype/plugins/TCode.name/46.

※ If you send a trackback by using an automatic blogging tool like QuickPost or so, then your ping will not be shown until the site owner approve it. This is for blocking spam-trackbacks. So please don't try to send pings repeatedly.

 

Comments

Great utility. Was wondering if you could add the 'Link this template to a file' option to your plugin. I tried to guess the format without success.
i.e. 'link' => 'post-content.txt'
in the .tmpl.add file.

I have a Module that is linked to a text file that is generated by a Main Index template. So when the Main Index outputs a new text file (.txt) the Module picks up the new template.

Hi
I've just tested it somehow. But it also failed.
After inserting "linked_file" field into default_template by roughly modifying tool, MT displayed an error message.(There are no linked file!) When loading MT(ie. loading all templates), if a template has "linked_file" field, MT would try to read template contents from that "linked_file". But on that time, there are no real "linked_file" exists. so error happeded.
I think it's exactly the reason why MT didn't allocate "linked_file" field in "lib/MT/default- template.pl" file.

Post a comment

☞ Your blog URL:

(A comment by authenticated (using TypeKey or OpenID) user will be shown immediately. Other comments need to be approved by the site owner. Until then, it won't appear on the entry. Thanks for waiting.)