I have a flexinode for a newsletter that I created where I don't want to display the node title, rather I would like the user to create a custom title. Will node.tpl.php control that? If so, can I modify node.tpl.php to not show titles for a specific flexinode?

In node.tpl.php I have this, but I must have the syntax wrong because I can still see the title.

<?php if ($page == 0): ?>
    <?php if(type != 'flexinode-2') :?>
		<h2 class="title"><a href="<?php print $node_url ?>" title="<?php print $title ?>"><?php print $title ?></a></h2>
	<?php endif; ?>
  <?php endif; ?>

Thanks.

Comments

nevets’s picture

In the code you show type != 'flexinode-2' should be $node->type != 'flexinode-2'.

You can also create a template file just for your content type, in this case you could copy node.tpl.php to node-flexinode-2.tpl.php and make the changes in the new file which would only apply to content of type flexinode-2.

cschall’s picture

I have the node-flexindode-2.tpl.php file to display my content, but I don't actually even have the title field displayed. I think that the node title is controlled differently which is why I thought that I needed to do the edit in the node.tpl.php file.

But that being said, I modified my file as indicated and I still see the title.

Here's the updated code.

<?php if ($page == 0): ?>
    <?php if($node->type != 'flexinode-2') :?>
		<h2 class="title"><a href="<?php print $node_url ?>" title="<?php print $title ?>"><?php print $title ?></a></h2>
	<?php endif; ?>
  <?php endif; ?>

THANKS.

nevets’s picture

The title is printed in one of two places depending in the context, a single node (i.e. page) or a list of nodes. The changes to node.tpl.php (or node-flexinode-2.tpl.php effect the title for the case of a list of nodes. For the title of a single node you will need to look at page.tpl.php. Look for $title.

cschall’s picture

Thanks so much!

lameei’s picture

I did a search for $title and found this:

 <?php 
		 if ($title): 
		 
		 if ($is_front){/* if we are on the front page use <h2> for title */
		 
		 print '<h2'. ($tabs ? ' class="with-tabs"' : '') .'>'. $title .'</h2>'; 
		 
		 }
		else {print '<h1'. ($tabs ? ' class="with-tabs"' : '') .'>'. $title .'</h1>';  /* otherwise use <h1> for node title */
		 }
		 
		 endif; ?>

will you please let me know how can i get rid of the page title?

jpmoriarty’s picture

I'm using Marvin, and want to change the title display on my pages of a certain type to a custom one. Marvin doesn't seem to *have* a page.tpl.php file, so I can't see anywhere to change it. Any ideas?

nevets’s picture

Marvin comes in several versions (different names) that work on various versions on Drupal.

For MarvinClassic, look in marvinclassic.theme for the function marvinclassic_node and look for $node->title,

Both Marvin 2K and Marvin 2K for PHPtemplate should have a node.tpl.php

jpmoriarty’s picture

okay i've edited chameleon.theme which is where i found the <h2> title line. My problem now is I don't know how to put what type of node is currently loaded into the if. I want to display a custom title (<h2>) on my 'content-property' nodes, so I put the following into chameleon.theme:

  if ($title) {
	if($node->type != 'content-property')
	    $output .= "<h2>$title</h2>";
	else
		$output .= "<h2>Custom Property page! $title</h2>";
  } 

but this did nothing - it just always displays $title. So then i even tried putting

  	echo "\n\n<h1>Node type is: ". $node->type ." </h1>\n\n";

into the code, but it doesn't display any text after the ':', suggesting that it can't access $node->type from that file.

Any suggestions?

nevets’s picture

You do node say which function you modified but from your comments it sounds like chameleon_page() where $node iis not available so you need to change your logic to something like this

 if ($title) {
$property_page = FALSE;
if ( arg(0) == 'node' && is_numeric(arg(1)) ) {
  $node = node_load(arg(1));   // Prior to 4.7 this line should be $node = node_load(array('nid' => arg(1)));
  if($node->type == 'content-property') {
    $property_page = TRUE;
  }
}

if( ! $property_page )
$output .= "<h2>$title</h2>";
else
$output .= "<h2>Custom Property page! $title</h2>";
}

which loads the node if a single node is being viewed.

jpmoriarty’s picture

Thanks for that - you were spot on.

My only problem now is that I wanted the title to include variables which, when in the node, I got thus:
<h2>".$node->field_road[0]['view'].", ".$node->field_postcode[0]['view'].", ".$node->title."</h2>
Of course, using that code in the theme file doesn't give any output. So is there a way I can access these variables from the theme file?

nevets’s picture

If you add this to your code
print '<code>' . print_r($node, TRUE) . '';

you will be able to see all the fields available in $node.

jpmoriarty’s picture

That seems to have fixed it! Thanks!