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.phpopen your config.php, and look for this line:
$config['process_whole_template'] = true;
change to:
$config['process_whole_template'] = false;
done on 1st step
2. Assign the news title to a smarty variableGo 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
{assign var='pagetitle' value=$entry->title}
3. Modify your templates to handle the new variableIm 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:
{content assign="capturedcontent"}
then replace {content} for:
{$capturedcontent}
look into the head section where the title tag resides, something like:
<title>{sitename} - {title}</title>
replace this piece of code for:
<title>{if isset($pagetitle)}{sitename} - {$pagetitle}{else}{sitename} - {title}{/if}</title>
4. Done, but understand whats happeningOn 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 theres 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 pageCreate 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 gets there hell see some content, or you can just go to the Option Tab and unmark the
show on menu option.
{news category="General" detailpage="news"}
Note that the "news" value on the detailpge parameter have to be the alias of the page youve 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 moreI generally let the <h1>/<h2> title tag inside my cmsms template, something like:
<body>
{breadcrumbs}
<h1>{title}</h1>
<div>{content}</div>
</body
In the case of news page the title on <h1> 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 lets use that {$pagetitle} again:
<body>
{breadcrumbs}
<h1>{$pagetitle}</h1>
<div>{content}</div>
</body
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 lets fix that:
<body>
{breadcrumbs}
<h1>
{if isset($pagetitle)}
{$pagetitle}
{else}
{title}
{/if}
</h1>
<div>{content}</div>
</body
7. Oops! The breadcrumbs...I just remembered another thing, the breadcrumbs.... this is bad because, dont matter the news detail Im reding and the breadcrumb will always show something like:
Home -> News
But I want something like:
Home -> News -> The title of the news
So, look what Ive done
<body>
if{isset($pagetitle)}
{breadcrumbs} -> {$pagetitle}
{else}
{breadcrumbs}
{/if}
<h1>
if{isset($pagetitle)}
{$pagetitle}
{else}
{title}
{/if}
</h1>
<div>{content}</div>
</body>
Of course, its not perfect because the last link of breadcrumbs, is not a link, its just text! Is it possible to change? Yes, but this will require editing the breadcrumbs tag, and im not on the mood to do it :>
Lets 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 youre read all that crap)
Regards
Viebig