Dissecting the Default Templates: Category Headings and Parameters
It’s time to move further down our default index template, don’t you think? So far, we’ve covered assigned variables and paths, variables, and weblog=.
In this article we’re going to start digging a bit deeper into the innards of ExpressionEngine; and we needn’t be too careful, she’s not fragile, I promise!
We’ve already worked with those major building blocks: paths and global variables, and the next four lines:
<ul id="navbar">
<li id="home"><a href="{homepage}" title="Home">Home</a></li>
<li id="about"><a href="{path={my_template_group}/about}" title="About">About</a></li>
<li id="archives"><a href="{path={my_template_group}/archives}" title="Archives">Archives</a></li>
<li id="contact">{encode="{webmaster_email}" title="Contact"}</li>
</ul>
utilize those in creating basic navigation to what may be the building blocks of your site. This is really just normal HTML using path statements and global variables. We’re all great learners here, so I’m not going to re-hash those concepts; they are linked above should you need to review how those work, and of course, in the documentation.
Last week we also touched on the weblog info tag as this is its second usage in this template. So we can continue on down the template immediately.
Now these next six lines are where things really get super-duper interesting. Ready for it?
{exp:weblog:category_heading weblog="{my_weblog}"}
<h2>{category_name}</h2>
{if category_description}
<p>{category_description}</p>
{/if}
{/exp:weblog:category_heading}
These lines introduce something new, as well as utilizing our previously-learned concepts. Let’s begin by figuring out this weird “exp:weblog:category_heading” tag. Easy, right? Just plug “exp:weblog:category_heading” into the search, and our first result will explain what this tag pair does and how to use it.
First, however, let us back up a tiny bit. Tag Pair? In ExpressionEngine there are two main types of tags: single tags, which work on their own to output or process information, and tag pairs. Tag pairs begin in some way and then always close with the exp statement and a forward slash, such as in the above: {/exp:weblog:category_heading}. Tag pairs are special because they don’t output anything on their own, but allow you to use variables inside of the tag pair to output your data how you want it to display. It’s all dynamic, but you say what goes where - fairly brilliant, yes?
Now, we know that the Weblog Category Heading Tag is a tag pair because it has an opening tag: {exp:weblog:category_heading} and a closing tag, which is the same but with a slash! {/exp:weblog:category_heading}. You might note that in the video tutorials, when Derek is using these tag pairs, he types in the opening and closing tag at the same time. This is a good habit because forgetting a closing tag is the cause of many template problems.
Here is the first time where we see that a single template can serve multiple purposes, in this case, a multi-entry page, and a category multi-entry page. The Weblog Category Heading Tag will only show up when viewing a Category Page and is ignored when visiting just the index, so our template now serves multiple functions in a single template!
We also learned in last week’s article that there are context specific variables and we can find those on our documentation page - these are variables made to work inside the Weblog Category Heading Tag, and require the surrounding tag pair for context, or they won’t know what information to display.
Now we learn about a new building block for ExpressionEngine: parameters. A parameter is a word, followed by an = sign, that appears within either a single tag or a tag pair. Parameters are essentially settings. All tags have default settings and, except in in rare cases (which are noted brightly in the documentation), are not required.
So in our Category Heading we see that we have the use of 3 parameters. As noted above, exceptions are noted quite brightly, and you can see that our weblog= parameter has an exception in some cases.
It is also important to note that you can always search for a parameter by using its syntax. For example, you can search for weblog= and find a list of all the tag pairs that take that parameter, so if you ever encounter a word followed by an equal sign, and you don’t know what it does - then go ahead and run a search for it!
There is another new item here and you’ll note it - {if} - ExpressionEngine allows the use of conditional global variables - which I’ll cover in a future article.
I shall leave you with this and continue on next week, be ready!


