Skip to main content
2 of 2
improved fornatting
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

I am unable to create a variable in template.php that I later want to use in node--content-type.tpl.php

In template.php I have created the following function.

function mytheme_preprocess_node__post_esl_material(&$variables){
  $variables['linking'] = 'yes baby';
}

In node--post-esl-material.tpl.php I am trying to print $linking, but it is not working. The reason I am trying this is because I heard from an expert in Drupal saying:

Template files are usually used to change the CSS. You do not want to put too much PHP logic here. The PHP logic is typically included in your template.php file.

Therefore the objective, after getting the above code to work, would be to:

  1. Create a $article variable in template.php.

  2. Swap the following code from node--post-esl-material.tpl.php into template.php.

    if (empty($content['field_article'])) {
      echo '';
    }
    else {
      echo '<div class="article">';
      echo '<h4>ARTICLE</h4>';
      echo '<div class="field_article">';
      print render($content['field_article']);
      echo '</div>';
      echo '</div>';
    }
    
  3. Print $article in node--post-esl-material.tpl.php and hence, have the PHP logic within template.php.

I am using Drupal 7 with the Stark theme.