ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Dynamic Page Title based on Weblog Title with embeded Templates

January 30, 2008 2:12pm

Subscribe [0]
  • #1 / Jan 30, 2008 2:12pm

    David Boyer

    12 posts

    I’m having difficulty determining how to dynamically generate page titles if the html <title> tag in inside a template that is embedded in all my other templates.

    For each of my templates I embedded a header and footer template:

    {embed="site/header"}
       ....weblog content….
    {embed="site/footer"}

    The embedded template header includes all the head content including the <title> and meta tags.

    All I want need to do is pull the weblog name from the currently displayed weblog into the embedded header template. Obviously a variable here is the trick but I’m at a lost how to get it working correctly. A push in the right direction would be greatly appreciated. Thanks!

  • #2 / Jan 30, 2008 3:46pm

    mayest

    293 posts

    You need to pass the variable to the embedded templates. In your main template do this:

    {embed="site/header" page_title="Title of the Page"}

    and then in your header you would have:

    <title>{embed:page_title}</title>

    You can pass a number of variables. I send the page title, stylesheet info, keywords, description, and template group name to my header.

  • #3 / Jan 30, 2008 4:20pm

    David Boyer

    12 posts

    Got it. Works particularly well when used in conjunction with Lisa Wess’ tip from her blog post: http://ellislab.com/blog/entry/seo_entry_titles_and_title/

    Therefore this is the title tag I’m using:

    <title> 
    {exp:weblog:entries weblog="{embed:pg_title}"  limit="1" disable="trackbacks|pagination|member_data|custom_fields|category_fields|categories" rdf="off"}
    {site_name}{if segment_1 == ""} - Welcome{/if} - {weblog} {if segment_3 != ""} - {title}{/if}
    {/exp:weblog:entries}
    </title>

    Where pg_title is being pulled from the single variable {weblog_short_name} in the template embedded variable.

    Thanks for the help!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases