Not a developer? Go to MovableType.com

Ask an Expert

Can I use the same template on multiple blogs?

Asked by John Smith
Posted October 16, 2013, in Featured.

Thanks!

Back

1 Answer

Charlie Gorichanaz

Charlie Gorichanaz on October 25, 2013, 2:14 a.m. Reply

This is pretty straightforward using Movable Type template modules and is explained in detail on the page Using Shared Templates. The basic idea is to put your shared code in a global or website template module and include that module within each blog’s individual templates.

Global template modules

Navigate to “Manage Global Templates” (System Overview -> Design -> Templates). The first listing is called “Template Modules,” and these are all the global template modules available for inclusion in other templates. Template modules and widgets (another type of shared template) are not published by themselves.

To create a new global module, click the “Create template module” link toward the top of this page. Copy your code into the body area and give the module a name.

To include the module within another template, use code like:

<$mt:Include module="Template Name"$>

To include the module within another template and override a blog level template module with the same name, use code like:

<$mt:Include module="Template Name" global="1"$>

Website template modules

Navigate to “Manage Website Templates” (Click website name -> Design ->Templates). The third listing is called “Template Modules,” and these are all the website template modules available for inclusion in other templates. These work similarly to global template modules described above.

To include a website module within another template in the same website, use code like:

<$mt:Include module="Template Name"$>

To include a website module within a child blog template, use code like:

<$mt:Include module="Template Name" parent="1"$>

or

<mt:SetVarBlock name="website_id"><mt:BlogParentWebsite><$mt:WebsiteID$></mt:BlogParentWebsite></mt:SetVarBlock>
<$mt:Include module="Website Header" website_id="$website_id"$>

See BlogParentWebsite for more information about the last example.

Blog template modules

Navigate to “Manage Blog Templates” (Click blog name -> Design ->Templates). The third listing is called “Template Modules,” and these are all the blog template modules available for inclusion in other templates. These work similarly to website template modules described above.

To include a blog module within another template in the same blog, use code like:

<$mt:Include module="Template Name"$>

To include a blog module within another template in another website or blog, use code like:

<$mt:Include module="Template Name" blog_id="1"$>

Note the blog ID can be found by finding the number that immediately follows blog_id= in the URL when viewing pages within that blog in the MT administration panel. This is the same value output by the template tag BlogID.

Complications when including a module in both blog and website contexts

If you have a website template module called “Header” and want to use it within a website level index template, you can include it with:

<$mt:Include module="Header"$>

To include that same module within a child blog’s index templates, you can include it with:

<$mt:Include module="Header" parent="1"$>

But what if you have this include within another module that is itself included at both the website and blog level?

<mt:IfWebsite>
  <$mt:Include module="Header"$>
<mt:Else>
  <$mt:Include module="Header" parent="1"$>
</mt:IfWebsite>

See also

Charlie Gorichanaz

Charlie joined Six Apart as a Japan based product manager for Movable Type in February 2014 after spending two years as a developer for 601am. Previously he was the web director of The Badger Herald while studying biochemistry at the University of Wisconsin-Madison.

Website: http://votecharlie.com/
Twitter: @CNG

Ask An Expert