Not a developer? Go to MovableType.com

News

Using template tag parameters

By Byrne Reese
Posted January 17, 2008, in Tips & Tricks.

From the "I didn't know you could do that" department:

So I was working with Beau on the implementation of a performance enhancement to Movable Type's search results and he showed me this really amazing trick that I doubt anyone knows about.

What we needed to do was suppress the comment and TrackBack counts from the search results page because a user in our community found that by removing them he dramatically sped up search results! However, we also wanted to use the same template module for displaying an entry's summary that we use everywhere else on the site. I thought we were going to have to create a special module just for search results, but then Beau showed me the following.

Did you know that you can pass parameters to template modules you include? I didn't. Within an include tag you can add any attribute and have that attribute passed to the included template as a variable. For example the include tag that includes the entry summary in the search results template would look like this:

<$MTInclude module="Entry Summary" hide_counts="1"$>

The hide_counts is a parameter that will be passed to the "Entry Summary" module as a variable. Then within the Entry Summary template module we can reference hide_counts like so:

<MTUnless name="hide_counts" eq="1">
    <MTIfCommentsActive>| <a href="<$MTEntryPermalink$>#comments">Comments 
        (<$MTEntryCommentCount$>)</a>
    </MTIfCommentsActive>
    <MTIfPingsActive>| <a href="<$MTEntryPermalink$>#trackback">TrackBacks 
        (<$MTEntryTrackbackCount$>)</a>
    </MTIfPingsActive>
</MTUnless>

The variable will also be made available to any templates that Entry Summary includes as well.

Very, very handy. Thank you Beau!

Back

9 Comments

Daniel Stout

Daniel Stout on January 17, 2008, 8:14 p.m. Reply

That’s an interesting and concise formulation. I’ve been using a slightly different technique to pass parameters — just setting a variable. To use your example:

<MTSetVar name=”hide_counts” value=”1”> <$MTInclude module=”Entry Summary”$>

Less concise, but it works about the same.

Jay Allen

Jay Allen on January 24, 2008, 12:17 a.m. Reply

Wait, you’re saying that you didn’t spec out that feature? I smell a Brad. :-)

I did happen to know about this feature, but then again, I actually read every line of the release notes. I’m a glutton. Nice work all.

wii ombouwen

wii ombouwen on May 21, 2011, 6:50 p.m. Reply

Idea is very good thanks

Pete Crowly

Pete Crowly on July 12, 2012, 7:58 a.m. Reply

I have a question, is it OK to use tag today when Google may consider them as a duplicate content?

Eli Te

Eli Te on August 5, 2012, 11:49 a.m. Reply

Interesting idea from Beau. I have to admit that. +1 for me.

superman stamina

superman stamina on September 6, 2012, 3:36 a.m. Reply

I actually didn’t know you could do that. It’s one of those things that’s going to come in very handy indeed!

Baufirmen

Baufirmen on October 10, 2012, 7:14 a.m. Reply

Did you know that you can pass parameters to template modules you include? I didn’t. Within an include tag you can add any attribute and have that attribute passed to the included template as a variable. For example the include tag that includes the entry summary in the search results template would look like this:

Tom Aegly

Tom Aegly on October 21, 2012, 8:04 p.m. Reply

Well, this looks too complicated for a newbie with Moveable type.

Sabine Crammer

Sabine Crammer on November 14, 2012, 9:09 p.m. Reply

What will happen if the search information is exactly within a comment? Isn’t it better to speed the site by other way and not to suppress all the comments from the search results?

Byrne Reese

Byrne Reese was previously the Product Manager of Movable Type at Six Apart, where he had also held positions as the Manager of Platform Technology and Product Manager for TypePad. Byrne is a huge supporter of the Movable Type user and developer community. He dedicates much of his time to promoting and educating people about Movable Type as well as building the tools and plugins for Movable Type that are showcased on Majordojo. He contributes regularly to open source; and he is an advocate for open protocols and standards like Atom and OpenID.

Website: http://profile.typekey.com/byrnereese