Jan 22
Implementing titles in ExpressionEngine
2007 at 10.49 am posted by Veerle
Implementing the title element in your ExpressionEngine templates is easy once you’re getting more familiar with the EE tags. For those still learning the first steps in EE, this will help you creating nice dynamic titles. I also share a tip on how to avoid a messy title bar in case the URL is broken. Learn and enjoy! ;)
Assign a variable
First thing you need to do is assigning a variable to your weblog's name. This will make things easy if you want to (re)use this name in your template.
![]()
The name of my (main) blog is "veerle_blog". So I assign the variable "my_weblog" to this name. Everywhere I use the variable "my_weblog" in the EE tags, EE will know that I'm referring to my main blog, "veerle_blog".
Implementing the EE title element
Between the opening and ending tag I've placed the following EE tags:
![]()
Let me clarify this. If you look at the titles of my pages, you'll see it's divided into 2 parts: the name of the blog and the title of the article separated by a pipe. In the first part I call the "weblog:info" tag where I use the variable "blog_title" which will display the "Full Weblog Name" name. In the second part I call the "weblog:entries" tag where I use the "title" variable which refers to the title of the article.
Avoiding messy title bars
A while ago I added an extra parameter to solve the layout errors when someone doesn't enter the full URL or if the URL got broken. This was simply done by adding require_entry="yes" in each EE exp weblogs:entries tag.
![]()
If you don't use this parameter, things will get messy in the title bar of the browser if the URL is broken. Adding this parameter solves the issue.
16served
1
Adding the disable parameter into that weblog tag would be a good idea just to cut down the number of queries just to receive a title for the page.
{exp:weblog:entries require_entry="yes" limit="1" disable="categories|custom_fields|member_data|pagination|trackbacks"}{title}{/exp:weblog:entries}2
Expression Engine is the greatest CMS to date - EE in combination with CodeIgniter is unstopable.
Another fine tutorial Veerle - I’m using the embedding feature to create the urls.
{embed="site/header" title="title goes here"}and call it from the header like this
<title>{if “{embed:title}” != “"}{embed:title}{if:else}Default title{/if}</title>There are so many ways to get things done in EE—all you need is creativity
3
My god, blogging tools have become more and more like language frameworks. *sigh*
4
John, That is really useful info. Small bit of code that is easily forgotten when using ‘exp:weblog:entries’ but will improve performance on a site.
Together with Veerle’s tip one can create a very lengthy tag but in the end it is all worth it :-).
5
@Henrik:
Expression Engine is so much more than a blogging tool:
HealthCity runs completely on EE and so does S2 Store. Don’t look like blogs now do they ;)
It’s abillity to use and reuse templates, weblogs, custom fields and relationships .. simply amazing.
6
I personally use Mambo / Joomla and handcoded titles into each page that I wanted to deviate from the template. I used it for my personal site and best of all it’s free (with support from a large community).
7
Hi there, First of all Veerle thanks for another great tutorial on EE. EE has to be in my mind the best CMS tool out there. I buy it for every site I ever create from now on.
I love the fact that if you want to create a blog type site then you can do so pretty much out of the box but it can also become SO much more.
Henrik said:
dotK - Just wondering, did you code the S2 site? Just asking as I was wondering if you did if you would have any kind of tutorial anywhere as to how you coded the shopping cart for the site. When I added something to the cart it looked as though the cart was actually part of EE as it still had the index.php in the URL.
At the moment I am using Mals-E as a shopping cart solution but would really like to have my own coded. Are you using the EE simple commerce module or something else?
Veerle - Sorry for hijacking the post slightly. I didn’t mean to do that it’s just that I couldn’t see a way to contact dotK directly unless I am going totally blind in my old age!!! Also didn’t know if dotK coded that site or not so didn’t want to go around emailing everyone and everybody.
I would also second Johns comment at the top of these comments and most definitely use the disable functions in EE so that your site uses up even less resources. EE is such a flexible beast!!! :-)
Best wishes,
Mark
8
I was just wondering if you would consider a tutorial on how you got your dates to be formatted on the little calendar graphic in your blog posts. Nothing I’ve tried works.
9
As always thanks for your insightful tips. I’m rebuilding my site using EE and every little tidbit helps.
10
Great tutorial!
Does anyone know how to make this work for page titles as well?
11
Wow!!, this is cool, I’ll surely use this one..
12
Yes, much more than a blogging tool, look at sites like sacunion.com, ilounge.com, gov.ca.gov, and the list could go on. ;) Biggest thing I love beyond the support, and features, is the security, unlike the mentioned Mambo / Joomla which are full of security issues on an on going basis, just like WordPress and others, EE has had 1 minor and quickly fixed security issue in the years that it has existed… enough said.
13
another awesome article....ever made one that isn’t?
never used the expression engine before, but it does look interesting
14
Thank you so much for this write-up Veerle! the page title beezneez has been the only thing that has bothered me for ages on my own site (hand coded at the moment). I’ll be implementing your code on my site during the weekend. Huge thanks!
15
<title>{exp:weblog:info weblog="{weblog}"}{blog_title}{/exp:weblog:info}{exp:weblog:entries weblog="{weblog}" orderby="date" sort="desc" limit="1" disable="custom_fields|member_data|pagination|trackbacks"}{if not_category_request} | {title}{/if}{if category_request}{categories} | {category_name}{/categories}{/if}{/exp:weblog:entries}</title>there is only bug: if category contains no entries title don’t display category name.
16
Thanks a lot, i’ve found your guides very useful.