EllisLab text mark
Advanced Search
     
Embed variables to display dynamic page titles
Posted: 11 December 2008 06:33 AM
Joined: 2008-11-11
39 posts

Is it ok to put EE tags in the embed variable like this?

{embed="includes/header" title="{exp:weblog:category_heading weblog="{my_weblog}"}
{category_name}{/exp:weblog:category_heading}"

I’m using this with a conditional in the embedded template to generate dynamic page titles (the <title> part of the HTML <head>). So, if the user is on the homepage they get the homepage title, if they’re on the article page they get the article title in the page title, and if they’re on a category page they get the category name in the page title. This is the conditional:

{exp:if_homepage}
{if is_homepage}
<title>This is the home page title</title>
{if:elseif segment_2 == ''}
<title>{embed:title}</title>
{if:elseif segment_3 == 'category'}
<title>{embed:title}</title>
{if:else}
<title>{exp:weblog:entries rdf="off" limit="1"}{blog_title} {title}{/exp:weblog:entries}</title>
{/if}
{
/exp:if_homepage} 

It all seems to work, but I want to check that having EE tags in the embed variable is OK to do?

 
Posted: 11 December 2008 11:49 AM   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2002-12-06
4781 posts

Sure…it’s my standard approach.

 Signature 

Get the missing EE2 owner’s manual - a complete guide to building an EE2 site.  It’s available in PDF or print.

 
Posted: 11 December 2008 11:54 AM   [ # 2 ]   [ Rating: 0 ]
Joined: 2008-11-11
39 posts

Thanks Boyink - glad to hear I’m on the right track.