Help - Search - Members - Calendar
Full Version: Customizing An Include For Different Templates
Movable Type Community Forum > Additional Resources > Tips and Tricks
dbe1996
I have applied Elise's article on creating a horizonal navigation bar to a site I'm working on, and it works great!

I'd like to put the html code in one template file that I can use throughout my site with an MTInclude tag (instead of having to maintain the navbar code in three or more separate templates). But I'm a little unsure how to do that.

Basically, I'd put the navbar code into a new template (e.g. "horizontal_navbar"). Then I'd use an MTInclude statement in my Main Index, Master Archive Index and About page templates to pull in the navbar code. But since the navbar code will be different based on which page has the focus, it will need to have conditional sections that are called in for the particular template. That's the part I don't know how to do.

Can anyone give me an example of how to apply this?

For example. Here's the basic code in Elise's article...

CODE
<div id="nav">

<a href="http://www.yoursite.com/about.html">about</a> | <a href="http://www.yousite.com/archives.html">archives</a> | <a href="http://www.yoursite.com/contact">contact</a> | <a href="http://www.yoursite.com/index.xml">rss</a>
</div>


In my navbar tempalte I'd need three or more sections of code like that, a section for each template I want to call it into...

CODE
If template = Main Index
<div id="nav">

<a href="http://www.yoursite.com/about.html">about</a> | <a href="http://www.yousite.com/archives.html">archives</a> | <a href="http://www.yoursite.com/contact">contact</a> | <a href="http://www.yoursite.com/index.xml">rss</a>
</div>

If template = Master Archive Index
<div id="nav">

<a href="http://www.yoursite.com/about.html">about</a> | <a href="http://www.yoursite.com/contact">contact</a> | <a href="http://www.yoursite.com/index.xml">rss</a>
</div>

If template = About page
etc...


What kind of code do I need to do the conditional stuff, where it pulls the correct navbar code for the right template?
mgs
I do something like this myself - have a central module template where certain parts are conditionally included.

I solved this by a combination of MTSetVar / MTGetVar and the Compare Plugin. In the root templates I set a certain variable to some value. Maybe in the main index it is set to "MI", in the category archive it is set to "CA", and so on. Then inside the included module template an MTIfEqual tag tests which of those values is set.

I have written several articles on the Compare Plugin. I think the first one to read should be...

Movable Type Weblog - Comparison needed for conditional Generation

It gives a basic introduction for this plugin. Depending on your exact needs, some other articles might be helpfull, too. I suggest you use MTLookup for finding those articles. For example

MTLookup search for: conditional

will list several articles, also from Learning Movable Type and Movalog, which will be interesting if you want to dive deeper into that subject.

Michael G. Schneider
arvind
Have a look at Variables and Conditional Display, in the entry, I talk about how I highlight different tabs depending on where you are using just one tab bar.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.