0

I am trying to remove a node title on a specific content type (Core Article) using its template file.

I don't want to use preprocess_node() hook that it's pretty straight forward but not of my liking due to I want to organize all my edited templates in my custom template folder.

What I did is this: I copied the node.tpl.php to my template folder under the folder "templates". I renamed that file to node--article.tpl.php. I edited the template file removing all the header section (which includes the title render function). Cleared the caches but the title is still there.

What am I doing wrong?

EDIT: Here is the code in my node--article.tpl.php

<article id="node-<?php print $node->nid; ?>" class="<?php  print $classes; ?> clearfix"<?php  print $attributes; ?>>
   <?php
      // Hide comments, tags, and links now so that we can render them later.
      hide($content['comments']);
      hide($content['links']);
      hide($content['field_tags']);
      print render($content);
      ?>  
      <?php
     if (!empty($content['field_tags']) || !empty($content['links'])):
      ?>  
   <footer>
      <?php
         print render($content['field_tags']);
         ?>
      <?php
         print render($content['links']);
         ?>  
   </footer>
   <?php
      endif;
    ?>  
    <?php
      print render($content['comments']);
    ?>

PS: Sorry for the code styling but I guess html5 tags are breaking the lines in stack exchange editor.

  • 1
    Maybe the template is not being used, are you sure that your tpl in your theme is being used? – Gianni Di Falco Aug 25 '16 at 10:53
  • please share the code of your template file,so we can debug it – vishal shah Aug 25 '16 at 11:03
  • @Gianni Di Falco How do I make sure of that? – pierostz Aug 25 '16 at 11:27
  • Break the file and empty cache xD i mean, if you look at bartik's node.tpl.php the $title variable is there so deleting it should not be printed, if still is printed so looks like your theme node--article.tpl.php file is not used. The file is named correctly? it is under the template folder of the active theme? – Gianni Di Falco Aug 25 '16 at 11:31
  • @vishal shah I edited the post and added the coding. – pierostz Aug 25 '16 at 11:34
1

Maybe you render article as full page then $title rendered in page.tpl.php

you just need override your content type page template, I mean duplicate page.tpl.php ( if you use bootsrap sub theme go to boostrap theme boostrap\template\system\page.tpl.php` file to your subtheme template forlder and rename it to page--article.tpl.php and remove title form it.

I mean remove these lines from it

  <?php if (!empty($title)): ?>
    <h1 class="page-header"><?php print $title; ?></h1>
  <?php endif; ?>

dont forget clear the cache

  • This is not necessarily correct. Title is rendered in node.tpl.php if node is not being rendered as a page. – lauriii Aug 25 '16 at 11:42
  • @lauriii if node render as full page page title getting rendered. – Yusef Mohamadi Aug 25 '16 at 11:48
  • @zhilevan Did exactly as you described. Copied the page.tpl.php and renamed to page--article.tpl.php and put it in my sub theme's folders. Removed the title rendering lines. Still showing. – pierostz Aug 25 '16 at 12:40
  • @pierostz So go to debuing phase, put some "die" in your code to be sure which file loaded ( put <?php die('in article page'); ?> and put <?php die('in node article');?> to be sure is your template files correctly. – Yusef Mohamadi Aug 26 '16 at 8:01
  • I am trying a more useful approach at this question. drupal.stackexchange.com/questions/212815/… Do you have any input on that? – pierostz Aug 26 '16 at 8:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.