How to display a node field value in a template file? I added a custom field in the ‘article‘ content type.
I am using bootstrap as a theme.
I want to print that field value as a css class in the h1 element of every node of type : article

So I duplicated the page.tpl.php in my subtheme template folder and changed the h1 code from :  

&lt;h1 class="page-header"&gt;&lt;?php print $title; ?&gt;&lt;/h1&gt;


to  

&lt;h1 class="page-header &lt;?php print $node-&gt;field_custom_field['und'][0]['value']; ?&gt;"&gt;&lt;?php print $title; ?&gt;&lt;/h1&gt;


The problem is that sometimes sometimes I get this error message  

    Notice: Undefined property: stdClass::$field_custom_field in include()  
(line 157 of /home/frost/sites/all/themes/subtheme/templates/page.tpl.php).


I have basic php knowledge, so my guess is I need to add a condition saying that the custom field is only printed if the template file is called when an article content type node is being viewed.  

How can I add this condition in the template file ?

Thank you
Duplicate node.tpl.php and rename it node--article.tpl.php and then it's just:

print render($content['field_custom_field']);


If you really want to stay on the page level you better use page--node--article.php and then you need to get hold of the $node object first somehow. Maybe take a look at Clive's answer here: https://drupal.stackexchange.com/a/32310/15055