News title on the title of the page for cmsms 1.5.2+
Posted: Sun Feb 01, 2009 3:57 am
Hello All,
This is a common request, that causes a lot of confusion since cmsms changed the way the templates are processed.
This recipe apply to just for the News Module, but any other modules that are template driven.
1. process_whole_template must be disabled in config.php
open your config.php, and look for this line:
change to:
done on 1st step
2. Assign the news title to a smarty variable
Go to Content -> News
click on "Detail Template" tab
edit your template (in most cases the default is named 'Sample', do it for every news detail template you have)
in the top of your template put this code
3. Modify your templates to handle the new variable
I´m talking about the templates on Layout -> Templates
first get rid of the useless {process_pagedata} if it exists on your first line
Let's capture the content... put this in templates first line:
then replace {content} for:
look into the head section where the title tag resides, something like:
replace this piece of code for:
4. Done, but understand what´s happening
On 1st step we disabled the process_whole_template directive, that,in a few words, make the the head section be processed before everything else, so when you call the news module on body, the head section is already done, so there´s no way to change the title.
By disabling this directive, we can set a variable inside any other place(modules, tags, content blocks, etc...), and it will be accessible in the head section by typing {$pagetitle}.
We can do a lot of cool things that way.
5. The best way available to display the news detail page
Create a News page and use the detailpage parameter, for example
You can put anything on the content(since the {content} will be replace for the news details). If you want this page to be visible on menu I reccomend that you add some content, like {news} so when the visitor get´s there he´ll see some content, or you can just go to the Option Tab and unmark the show on menu option.
Note that the "news" value on the detailpáge parameter have to be the alias of the page you´ve created. (you can find the alias of the page on the Options tab when editing a page, or set it manually when creating a page(because it wont show the alias if the page is not saved yet, but you can save an go back and an automatic alias will be generated. The page alias is an important variable that is used in the URL of the page and in some modules calls)
6. A little bit more
I generally let the / title tag inside my cmsms template, something like:
In the case of news page the title on will be just "News"(title I defined in when editing the page), dont matter what news detail the visitor is on. We can change that.
so let´s use that {$pagetitle} again:
Ok.. but, think with me, this will only work if the visitor is seeing a news detail page, else it will be blank and will trigger a php notice since we did not populate the {$pagetitle} var anywhere... so let´s fix that:
7. Oops! The breadcrumbs...
I just remembered another thing, the breadcrumbs.... this is bad because, dont matter the news detail I´m reding and the breadcrumb will always show something like:
But I want something like:
So, look what I´ve done
Of course, it´s not perfect because the last link of breadcrumbs, is not a link, it´s just text! Is it possible to change? Yes, but this will require editing the breadcrumbs tag, and i´m not on the mood to do it :>
Let´s hope that in a near future this things can be achivied in a easier way.
Please, comment it, feedback is always appreciated.
And a special cheer to people that read this whole post! (write cheers on the end of your reply so I know that you´re read all that crap)
Regards
Viebig
This is a common request, that causes a lot of confusion since cmsms changed the way the templates are processed.
This recipe apply to just for the News Module, but any other modules that are template driven.
1. process_whole_template must be disabled in config.php
open your config.php, and look for this line:
Code: Select all
$config['process_whole_template'] = true;
Code: Select all
$config['process_whole_template'] = false;
2. Assign the news title to a smarty variable
Go to Content -> News
click on "Detail Template" tab
edit your template (in most cases the default is named 'Sample', do it for every news detail template you have)
in the top of your template put this code
Code: Select all
{assign var='pagetitle' value=$entry->title}
I´m talking about the templates on Layout -> Templates
first get rid of the useless {process_pagedata} if it exists on your first line
Let's capture the content... put this in templates first line:
Code: Select all
{content assign="capturedcontent"}
Code: Select all
{$capturedcontent}
Code: Select all
<title>{sitename} - {title}</title>
Code: Select all
<title>{if isset($pagetitle)}{sitename} - {$pagetitle}{else}{sitename} - {title}{/if}</title>
On 1st step we disabled the process_whole_template directive, that,in a few words, make the the head section be processed before everything else, so when you call the news module on body, the head section is already done, so there´s no way to change the title.
By disabling this directive, we can set a variable inside any other place(modules, tags, content blocks, etc...), and it will be accessible in the head section by typing {$pagetitle}.
We can do a lot of cool things that way.
5. The best way available to display the news detail page
Create a News page and use the detailpage parameter, for example
You can put anything on the content(since the {content} will be replace for the news details). If you want this page to be visible on menu I reccomend that you add some content, like {news} so when the visitor get´s there he´ll see some content, or you can just go to the Option Tab and unmark the show on menu option.
Code: Select all
{news category="General" detailpage="news"}
6. A little bit more
I generally let the / title tag inside my cmsms template, something like:
Code: Select all
</__body>
{breadcrumbs}
<h1>{title}</h1>
<div>{content}</div>
<__body
so let´s use that {$pagetitle} again:
Code: Select all
</__body>
{breadcrumbs}
<h1>{$pagetitle}</h1>
<div>{content}</div>
<__body
Code: Select all
</__body>
{breadcrumbs}
<h1>
{if isset($pagetitle)}
{$pagetitle}
{else}
{title}
{/if}
</h1>
<div>{content}</div>
<__body
I just remembered another thing, the breadcrumbs.... this is bad because, dont matter the news detail I´m reding and the breadcrumb will always show something like:
Code: Select all
Home -> News
Code: Select all
Home -> News -> The title of the news
Code: Select all
</__body>
if{isset($pagetitle)}
{breadcrumbs} -> {$pagetitle}
{else}
{breadcrumbs}
{/if}
<h1>
if{isset($pagetitle)}
{$pagetitle}
{else}
{title}
{/if}
</h1>
<div>{content}</div>
<__body>
Let´s hope that in a near future this things can be achivied in a easier way.
Please, comment it, feedback is always appreciated.
And a special cheer to people that read this whole post! (write cheers on the end of your reply so I know that you´re read all that crap)
Regards
Viebig