0

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.

0

These are the steps I would take to resolve (re-trying after each step)

  1. Clear theme registry cache - /admin/config/development/performance - Clear Cache
  2. Use the more general function mytheme_preprocess_node($variables), clear cache, try again

If the more general function works, your issue is likely that you have incorrectly named the template, try:kpr($vars['theme_hook_suggestions']) if you have the Devel Module installed. If not, you should. Otherwise you can print_r($vars['theme_hook_suggestions']). Is your template included in there?

  • When I try using mytheme_preprocess_node($variables) and refresh my site (I am developing my site on localhost) the site goes completely blank. This is the reason why I was trying to do it with the other function. Do you know why my site goes blank if I try using mytheme_preprocess_node($variables) in template.php? – Blas86 Jul 6 '13 at 10:22
0

I have found the mistake. I was using mytheme_preprocess_node($variables) twice within the template.php. I have included $variables['linking'] = 'yes baby'; within the first function and deleted the second one and know it works fine. Thanks for your help.

  • That's why you got a white screen (you should turn on some debugging in your development environment) after following the steps I gave, but it doesn't answer your original question (unless using hook_node_preprocess() is acceptable. – Chris Rockwell Jul 6 '13 at 13:25
  • It doesn't solve the original question but using the function mytheme_preprocess_node(&$vars) works perfectly so I haven't tried doing it with the original function mytheme_preprocess_node__post_esl_material(&$variables). – Blas86 Jul 6 '13 at 18:32

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.