News title on the title of the page for cmsms 1.5.2+

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
viebig

News title on the title of the page for cmsms 1.5.2+

Post by viebig »

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:

Code: Select all

$config['process_whole_template'] = true;
change to:

Code: Select all

$config['process_whole_template'] = false;
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

Code: Select all

{assign var='pagetitle'  value=$entry->title}
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:

Code: Select all

{content assign="capturedcontent"}
then replace {content} for:

Code: Select all

{$capturedcontent}
look into the head section where the title tag resides, something like:

Code: Select all

<title>{sitename} - {title}</title>
replace this piece of code for:

Code: Select all

<title>{if isset($pagetitle)}{sitename} - {$pagetitle}{else}{sitename} - {title}{/if}</title>
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.

Code: Select all

{news category="General" detailpage="news"}
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:

Code: Select all

</__body>
{breadcrumbs}
<h1>{title}</h1>
<div>{content}</div>
<__body
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:

Code: Select all

</__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 let´s fix that:

Code: Select all

</__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 I´m reding and the breadcrumb will always show something like:

Code: Select all

Home -> News
But I want something like:

Code: Select all

Home -> News -> The title of the news 
So, look what I´ve done

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>
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
Last edited by viebig on Sat Feb 07, 2009 11:33 pm, edited 1 time in total.
User avatar
Trenia
Forum Members
Forum Members
Posts: 79
Joined: Thu Dec 11, 2008 12:48 pm
Location: Norway

Re: News title on the title of the page for cmsms 1.5.2+

Post by Trenia »

Code: Select all

<title>{if isset($pagetitle}}{sitename} - {$pagetitle}{else}{sitename} - {title}{/if}</title>
This code creates a string smarty error....!

I believe the correct code should be:

Code: Select all

<title>{if isset($pagetitle)}{sitename} - {$pagetitle}{else}{sitename} - {title}{/if}</title>
and here`s another spelling mistake:

Code: Select all

{news category="General' detailpage="news"}
correct one is:

Code: Select all

{news category="General" detailpage="news"}
Last edited by Trenia on Sun Feb 01, 2009 1:00 pm, edited 1 time in total.
viebig

Re: News title on the title of the page for cmsms 1.5.2+

Post by viebig »

Thank you Trenia.. I wrote that on the fly without testing.

I corrected everything in the original post. Hope that helps!
Jean le Chauve

Re: News title on the title of the page for cmsms 1.5.2+

Post by Jean le Chauve »

Hi,
This code creates a string smarty error....!

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>
I believe the correct code should be:

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>
Your code work nice for the title of the page but don't work into the body.
If i use {$pagetitle} without "if isset", i receive this notice : Notice: Undefined index: pagetitle in /xxx/xxx/www/cms1.5.2/tmp/templates_c/%%EF^EF3^EF386C0A%%tpl_body%3A21.php on line 22 (where i put {$pagetitle}
viebig

Re: News title on the title of the page for cmsms 1.5.2+

Post by viebig »

Hi Jean,

I just fixed the original post, thank you.

Try to disable error notices on PHP and tell me is the {$pagetitle} show something, if not let me know.

Also, if possible paste your template relevant code here so I can reproduce the error. I experienced something like that before, I know a solution.

Regards
Last edited by viebig on Mon Feb 02, 2009 2:06 pm, edited 1 time in total.
viebig

Re: News title on the title of the page for cmsms 1.5.2+

Post by viebig »

Forget it.

Of course that this notice will appear if $pagetitle is not set at all, and php notices are enabled.

let´s correct this by always using isset() function

Code: Select all

<h1>{if isset($pagetitle)}{$pagetitle}{else}{title}{/if}</h1>
Last edited by viebig on Mon Feb 02, 2009 6:27 pm, edited 1 time in total.
Jean le Chauve

Re: News title on the title of the page for cmsms 1.5.2+

Post by Jean le Chauve »

Hi Viebig, thanks for your response.
 
layout template :

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<__html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr_FR">
<head>
<title>{if isset($pagetitle)}{sitename} - {$pagetitle}{else}{sitename} - {title}{/if}{$pagetitle}</title>

{metadata}
{stylesheet}
{cms_selflink dir="start" rellink=1}
{cms_selflink dir="prev" rellink=1}
{cms_selflink dir="next" rellink=1}
{literal}
<__script__ type="text/JavaScript">
<!--
//pass min and max -measured against window width
function P7_MinMaxW(a,b){
	var nw="auto",w=document.documentElement.clientWidth;
	if(w>=b){nw=b+"px";}if(w<=a){nw=a+"px";}return nw;
}
//-->
</__script>
<!--[if lte IE 6]>
<style type="text/css">
{* The min and max page width for Internet Explorer is set here. For other browsers it's in the stylesheet "Layout: Top menu + 2 columns" *}
#pagewrapper {width:expression(P7_MinMaxW(720,1900));}
#container {height: 1%;}
</style>
<![endif]-->
<!--[if lte IE 6]>
<link rel="stylesheet" media="all" type="text/css" href="uploads/files/menus/pro_dropline_2/pro_left_right_ie6.css" />
<![endif]-->
{/literal}
</head>
</__body>
<div id="pagewrapper">
{* start accessibility skip links *}
<ul class="accessibility">
<li>{anchor anchor='menu_vert' title='Skip to navigation' accesskey='n' text='Skip to navigation'}</li>
<li>{anchor anchor='main' title='Skip to content' accesskey='s' text='Skip to content'}</li>
</ul>
{* end accessibility skip links *}
<hr class="accessibility" />
{* Horizontal ruler that is hidden for visual browsers by CSS *}
{* Start Header, with logo image that links to the default start page. Logo image is changed in the stylesheet  "For template: Left menu + 1 column" *}
<div id="header">
<h1>{cms_selflink dir="start" text="$sitename"}</h1>
<hr class="accessibility" />
</div>
{* End Header *}
{* Start Navigation *}
<div id="menu_vert">
<h2 class="accessibility">Navigation</h2>
{menu template='proline' start_level="1" number_of_levels='2'}
<hr class="accessibility" />
</div>
{* End Navigation *}
{* Start Content (Navigation and Content columns) *}
   <!--start content-->
<div id="content">
<!--start sub-content-->
           <div id="sub-content">
            <div id="main">
            {* Start Breadcrumbs *}
  {get_template_vars}             
<p id="breadcrumb">
{breadcrumbs starttext='Vous êtes ici ' root='Home' delimiter='»'}{if isset($pagetitle)} -> {$pagetitle}{/if}{* End Breadcrumbs *}
   </p>
<div id="main-content">
<h1>
{if isset($pagetitle)}
   {$pagetitle}
{else}
   {title}
{/if}
</h1>
{content} </div><!--fin main-content--></div><!--finContent-->
<div id="sidebar">
{search lang="fr_FR" searchtext="Je cherche" }
<div id="nav-droite">{menu start_level='3' }</div>
{* To do *}
<form id="membres" method="post" action="">
</form>
{* End to do *}
<a id="inscription" href=""> Inscrivez-vous </a>
<h2><span>Les news</span></h2>
{news detailpage="news" summarytemplate="newsDesign" detailtemplate="Sample" lang="fr_FR"}
<h3>
Pivamus imperdiet -
<span>13Nov2008</span>
</h3>
<p> Orci eget eros. Praesent magna. Donec a quam. Donec ornare. Ut dolor justo, condimentum sit amet, rutrum id, consectetuer id, nisi. Fusce non augue. Donec non dolor. Donec sed odio. Suspendisse tincidunt lacus nec arcu. </p>
</div>
<div class="spacer"/>
</div>
</div>
<div id="spacer-footer"/>
</div>
<div id="footer">{global_content name='footer'}
</div>
<__body>
</__html>
content page news

Code: Select all

{news category="General" detailpage="news"}
detail template

Code: Select all

{assign var='pagetitle' value=$entry->title}
{if $entry->postdate}
	<div id="NewsPostDetailDate">
		{$entry->postdate|cms_date_format}
	</div>
{/if}
<h3 id="NewsPostDetailTitle">{$entry->title}</h3>
<hr id="NewsPostDetailHorizRule" />
{if $entry->summary}
	<div id="NewsPostDetailSummary">
		<strong>
			{eval var=$entry->summary}
		</strong>
	</div>
{/if}
{if $entry->category}
	<div id="NewsPostDetailCategory">
		{$category_label} {$entry->category}
	</div>
{/if}
{if $entry->author}
	<div id="NewsPostDetailAuthor">
		{$author_label} {$entry->author}
	</div>
{/if}
<div id="NewsPostDetailContent">
	{eval var=$entry->content}
</div>
{if $entry->extra}
	<div id="NewsPostDetailExtra">
		{$extra_label} {$entry->extra}
	</div>
{/if}
<div id="NewsPostDetailPrintLink">
	{$entry->printlink}
</div>
{if $return_url != ""}
<div id="NewsPostDetailReturnLink">{$return_url}</div>
{/if}
{if isset($entry->fields)}
  {foreach from=$entry->fields item='field'}
     <div class="NewsDetailField">
        {if $field->type == 'file'}
	  {* this template assumes that every file uploaded is an image of some sort, because News doesn't distinguish *}
          <img src="{$entry->file_location}/{$field->value}"/>
        {else}
          {$field->name}: {eval var=$field->value}
        {/if}
     </div>
  {/foreach}
{/if}
{get_template_vars}
I put {get_template_vars} into tthe layout template AND into the menu template.

The first come from the result of the {get_template_vars} layout and the second come from the the menu template.
Into the first, $pagetitle is not populate but in the title yes ({if isset($pagetitle)}{sitename} - {$pagetitle}{else}{sitename} - {title}{/if}{$pagetitle}
Here is the link for my test, the news are into the right sidebar : http://www.promojeunes.be/cms1.5.2/

[edit]It's a multi domain OVH[edit]Iwww.promojeunes.be is a cmsms. I made an new installation into cms1.5.2. Perhaps this make conflict. I must test into a clean installation.
----------------------------------------------

Cms Version: 1.5.2

Installed Modules:

    * CMSMailer: 1.73.14
    * FileManager: 0.4.3
    * MenuManager: 1.5.3
    * ModuleManager: 1.2.1
    * News: 2.9.2
    * nuSOAP: 1.0.1
    * Printing: 0.2.6
    * Search: 1.5.2
    * ThemeManager: 1.0.8
    * TinyMCE: 2.4.11
    * CGExtensions: 1.15
    * Uploads: 1.4
    * Download: 0.2b
    * LightBox: 1.0.1
    * ConfigGUI: .2
    * CGFeedMaker: 1.0.4
    * bMenu: 0.4.6
    * Captcha: 0.3.2


Config Information:

    * php_memory_limit:
    * process_whole_template: false
    * max_upload_size: 16000000
    * default_upload_permission: 664
    * assume_mod_rewrite: false
    * page_extension:
    * internal_pretty_urls: false
    * use_hierarchy: false


Php Information:

    * phpversion: 5.2.6
    * md5_function: On (Vrai)
    * gd_version: 2
    * tempnam_function: On (Vrai)
    * magic_quotes_runtime: Off (Faux)
    * memory_limit: 32M
    * max_execution_time: 30
    * safe_mode: Off (Faux)
    * session_save_path: /tmp (1777)


Server Information:

    * Server Api: cgi
    * Server Db Type: MySQL (mysql)
    * Server Db Version: 5.0.68


----------------------------------------------
Last edited by Jean le Chauve on Mon Feb 02, 2009 8:45 pm, edited 1 time in total.
viebig

Re: News title on the title of the page for cmsms 1.5.2+

Post by viebig »

are you sure process_whole_template is false in config.php
Jean le Chauve

Re: News title on the title of the page for cmsms 1.5.2+

Post by Jean le Chauve »

Yes, it is.
Config Information:

    * php_memory_limit:
    * process_whole_template: false

www.promojeunes.be is a cmsms. I made an new installation into cms1.5.2. Perhaps this make conflict. I must test into a clean installation.
Last edited by Jean le Chauve on Mon Feb 02, 2009 10:53 pm, edited 1 time in total.
viebig

Re: News title on the title of the page for cmsms 1.5.2+

Post by viebig »

could be... try this:

capture the news call on the top of your template:

Code: Select all

{capture assign="newscontent"}{news detailpage="news" summarytemplate="newsDesign" detailtemplate="Sample" lang="fr_FR"}{/capture}
and substitute your news module call by

Code: Select all

{$newscontent}
let us know if it works!

Regards
Jean le Chauve

Re: News title on the title of the page for cmsms 1.5.2+

Post by Jean le Chauve »

I'm sorry, Viebig, but nothing work.
I made a new instalation on the server root, I have tested all your solutions, but it seems impossible to populate $pagetitle into the body.  :'(
Is there anybody who made a success ?
viebig

Re: News title on the title of the page for cmsms 1.5.2+

Post by viebig »

Jean, I wont give up on you.

May I have access to that server as cmsms admin?

Anyway in a few days I will create a subdomain on my server, and let the admin passwd here, so you can review my solution online.

Regards
viebig

Re: News title on the title of the page for cmsms 1.5.2+

Post by viebig »

try just one more thing.. use right below body

Code: Select all

{content assign='mycontent'}
and  replace {content} by

Code: Select all

{$mycontent}
JeremyBASS

Re: News title on the title of the page for cmsms 1.5.2+

Post by JeremyBASS »

just a thought but if you have pretty urls on why not replace the title with


{if $content_id eq '72'}{capture assign='URLSS'}{URLhere}{/capture}
{assign var=newstitle value=$URLSS|replace:'.html':''|regex_replace:'/(http.*?\/72\/)/':''|replace:'-':' '}
    {$newstitle|lower|capitalize:true}
{else}
{title}
{/if} | {$ntmp}

where 72 isthe content_id of the page your details are for news

and if you have / instead of .html

use

|replace:'/' instead

and a UDT called URLhere
$urlBASE = "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];
if (!empty($_SERVER["QUERY_STRING"]))
  $urlBASE .= "?".$_SERVER['QUERY_STRING'];

$urls = str_replace("index.php?page=", "", $urlBASE);
echo $urls;
that would work... and not one bit of the files need to be changed.... ;)

cheers
jeremyBass

some proof...
http://www.corbensproducts.biz/news/10/ ... omers.html
Last edited by JeremyBASS on Fri Feb 06, 2009 3:37 am, edited 1 time in total.
viebig

Re: News title on the title of the page for cmsms 1.5.2+

Post by viebig »

Hi Jeremy!

Great solution, but has 2 problems:

1. The news pretty urls dont support accents and special chars, and any news title with accents would be generated wrong. ( I reported this to calguy)

2. And even id news module is patched, some chars are not URL standardized, so it not would fit another languages well.

My solution works, and it´s not mine, it´s a compilation.

Conclusions:

1. English is the web language
2. You´re really a crazy programmer(in the good sense) to think about that workaround. Really nice!  :)

Regards
Post Reply

Return to “Tips and Tricks”