Setting your page's title to be the News title

One shortcoming (I believe) of CMSMS is that when you click on a news item, the news title doesn't become the page's title. The reason for this is that by default, the page that the summary is on becomes the page that the news details are on, just switching out the content. You can redirect this to any page you want, but that doesn't help us get the right title for the page. This simple tutorial will fix this.

Add the following to the end of your News detail template:

{assign var='alt_title' value=$entry->title}

Now edit your site template and replace:

<title>{sitename} - {title}</title>


{if isset($alt_title)}
<title>{sitename} - {$alt_title}</title>
<title>{sitename} - {title}</title>

That's it! This assumes that 'process_whole_template' is set to false in config.php (the default). This setting will cause the <body> of the template to be processed before the <head> to ensure that we capture the title from the body before it's needed in the head.

This will work with other modules too, such as CGBlog, CGCalendar, Products, and just about anything with summary and detail templates with small modifications.

On a side note, if you are using AdvancedContent, you can create a one-line content block called alt_title, and set an alternate title for any page. If you aren't using AdvancedContent, you can go to your page's 'Options' tab and place the following in the section called "Smarty data or logic that is specific to this page:"

{assign var="alt_title" value="Your New Title"}

I just wish the {title} and the News module would work together.. It's just a one-liner code change for both of these to support this by default.