You are looking at archived content. The hot new stuff is happening at Veerle's blog 3.0. You should check it out!

Jan 22

Implementing titles in ExpressionEngine

2007 at 10.49 am posted by Veerle Pieters

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.

Implementing titles in Expression Engine - Assign a variable

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:

Implementing the EE title element

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.

Implementing titles in ExpressionEngine - Avoiding messy title bars

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

gravatar

1

permalink this comment John Henry Donovan Mon Jan 22, 2007 at 11.33 am

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}


gravatar

2

permalink this comment dotK Mon Jan 22, 2007 at 11.33 am

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


gravatar

3

permalink this comment Henrik Lied Mon Jan 22, 2007 at 03.16 pm

My god, blogging tools have become more and more like language frameworks. *sigh*


gravatar

4

permalink this comment Dion Mon Jan 22, 2007 at 03.58 pm

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 :-).


gravatar

5

permalink this comment dotK Mon Jan 22, 2007 at 04.17 pm

@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.


gravatar

6

permalink this comment Gavin the Photographer Mon Jan 22, 2007 at 05.58 pm

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).


gravatar

7

permalink this comment Mark Bowen Mon Jan 22, 2007 at 09.45 pm

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:

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.

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


gravatar

8

permalink this comment Jessiegirl Tue Jan 23, 2007 at 02.49 am

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.


gravatar

9

permalink this comment Rob Tue Jan 23, 2007 at 04.49 am

As always thanks for your insightful tips. I’m rebuilding my site using EE and every little tidbit helps.


gravatar

10

permalink this comment Andy Thu Jan 25, 2007 at 03.07 am

Great tutorial! 

Does anyone know how to make this work for page titles as well?


gravatar

11

permalink this comment Trisha Parks Thu Jan 25, 2007 at 07.46 am

Wow!!, this is cool, I’ll surely use this one..


gravatar

12

permalink this comment Brian James Fri Jan 26, 2007 at 07.50 am

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.


gravatar

13

permalink this comment David G. Paul Fri Jan 26, 2007 at 09.10 pm

another awesome article….ever made one that isn’t?

never used the expression engine before, but it does look interesting


gravatar

14

permalink this comment MrMunson Sat Jan 27, 2007 at 11.35 am

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!


gravatar

15

permalink this comment Fluxsoap Fri Feb 9, 2007 at 08.05 pm

<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.


gravatar

16

permalink this comment Andrew Ingram Mon Feb 12, 2007 at 12.42 am

Thanks a lot, i’ve found your guides very useful.



Commenting is not available in this weblog entry.

Flickrness

buy something from my Amazon wishlist