Skip to main content
improved fornatting
Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

In template.phptemplate.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.phpnode--post-esl-material.tpl.php I am trying to:

print $linking;

It print $linking, but it is not working. The reason I am trying this is because I heard from an expert in Drupal that "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.".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, for example:

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

    $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 template$article in node--post-esl-material.tpl.php: and hence, have the PHP logic within 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, haveI am using Drupal 7 with the PHP logic within template.phpStark theme.

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;

It is not working. The reason I am trying this is because I heard from an expert in Drupal that "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, for example:

  1. Create a variable in template.php:

    $article

  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.

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.

Source Link

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;

It is not working. The reason I am trying this is because I heard from an expert in Drupal that "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, for example:

  1. Create a variable in template.php:

    $article

  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.