hi,

when i enter a node, the node title is shown twice since i have:
page.tpl.php
print $title
then
node.tpl.php
print $title
(http://www.physiotek.com/drupal/content/les-exercices-et-le-post-partum)

i dont want to delete simply one of the two print $title since when i enter, for exemple, the blog page i have
page.tpl.php
title=blog
then
node.tpl
title=first blog title
title=second blog title
and so on
(http://www.physiotek.com/drupal/blog)

so it's usefull to have both

and i cant do:
page.tpl.php
$pagetitle=$title
print $title
then
node.tpl.php
if ($title != $pagetitle) print $title;
since i would like to keep the second $title (the node.tlp one)
if you look at the design you will understand why

any idea how to remove the first $title (the page.tpl one) when both are equals??

thanks,
pht3k

Comments

ronan’s picture

Usually you do not print the title within node.tpl.php unless you are generating the teaser for the node. Normally you would use code such as:

if( !$page ) {
  print $title;
}

the $page variable contains 1 when the node detail page is being rendered and 0 when the teaser is being generated (like on your blog page)

In your case since you are trying to suppress the title in page.tpl.php and not the one in node.tpl.php, you will need to do a little more.

You can take advantage of the fact that page.tpl.php is actually called after node.php.tpl. What I do is set a global variable in node.tpl.php which I then read in page.tpl.php. It's a little hacky but it works.

in node.tpl.php put:

if( $page ) {
  $GLOBALS['suppress_title'] = true;
}

and in page.tpl.php add:

if( !$GLOBALS['suppress_title']  ) {
  print $title;
}

Hope this helps
------------------------------------
Ronan - Gorton Studios - http://www.gortonstudios.com/

------------------------------------
Ronan
Founder - NodeSquirrel - https://www.nodesquirrel.com/
Agency Tools Lead - Pantheon - https://www.pantheon.io/

physiotek’s picture

your code works like a charm!!! thanks a lot!!

in fact the reasoning with my code was ok too but i thought that the page.tpl was loaded before the node.tpl... so i thought i would not work!

that'S why i said:

and i cant do:
page.tpl.php
$pagetitle=$title
print $title
then
node.tpl.php
if ($title != $pagetitle) print $title;
since i would like to keep the second $title (the node.tlp one)
if you look at the design you will understand why

anyway your code looks more professional :)

thanks again,
pht3k

physiotek’s picture

well i thought taht everything was ok but with some nodes it's not working.
for exemple this node: http://www.physiotek.com/drupal/node/367
it appears that $page equals nothing while it should be 1 to avoid showing twice the title
all nodes that have this particularity are those created from aggregation.
now how can i change this value for those nodes?
i will asK also in the aggregation module pages.
i will keep you informed.

pht3k

physiotek’s picture

forget about this; i was coding the wrong files...
sorry i completely forgot about the alternate tpl files (node-aggregation_feed.tpl.php/node-aggregation_item.tpl.php).
i must have spent 3 hours for nothing
argh

doublejosh’s picture

Used your idea in combination with a title toggle check box.

First add a field to the content type with a CCK single on off check box. Set the key value pair to 1|Hide Title and 0|Show Title, though only hide will show up as the label.

Then add this to node.tpl.php
<?php if($field_hide_title[0]['value']==1) { $GLOBALS['suppress_title'] = true; } ?>

Then add this to page.tpl.php
<?php if (!$GLOBALS['suppress_title'] && $title): ?><h1 class="title"><?php print $title; ?></h1><?php endif; ?>

Thank god. This has always been an annoyance for me. Now I can do it on a node by node basis.

physiotek’s picture

nice! maybe u should release it as a module?

summit’s picture

Very interested in this as a module.
Would it also be possible to set the title with these options AND to have it only shown on a certain content-type, or may be only on certain taxonomy term?

Thanks a lot in advance for your reply!

Greetings,
Martijn
if you appreciate e-development work, please place a link from your site to www.trekking-world.com