0

I´ve tried in my Drupal 7 site with this:

<?php print render($content['taxonomy_vocabulary_11']); ?>

But it doesn´t print anything at all. I´ve tried this too, and it prints out an error:

<?php print $node['taxonomy_vocabulary_11']; ?>

The error is: Fatal error: Cannot use object of type stdClass as array in /public_html/sites/all/themes/liga/templates/node--jornadas.tpl.php on line 30

Using Devel, I´ve get this information, and it seems that the print statement is correct:

... (Array, 16 elements)
taxonomy_vocabulary_6 (Array, 16 elements)
taxonomy_vocabulary_7 (Array, 16 elements)
taxonomy_vocabulary_11 (Array, 17 elements)
#theme (String, 5 characters ) field
#weight (String, 2 characters ) 10
#title (String, 4 characters ) tags
#access (Boolean) TRUE
#label_display (String, 6 characters ) hidden
#view_mode (String, 4 characters ) full
#language (String, 3 characters ) und
#field_name (String, 22 characters ) taxonomy_vocabulary_11
#field_type (String, 23 characters ) taxonomy_term_reference
#field_translatable (String, 1 characters ) 0
#entity_type (String, 4 characters ) node
#bundle (String, 19 characters ) jornadas_realizadas
#object (Object) stdClass
#items (Array, 2 elements)
#formatter (String, 28 characters ) taxonomy_term_reference_link
0 (Array, 4 elements)
#type (String, 4 characters ) link | (Callback) link();
#title (String, 8 characters ) colegios
#href (String, 17 characters ) taxonomy/term/262
#options (Array, 2 elements)
1 (Array, 4 elements)
#type (String, 4 characters ) link | (Callback) link();
#title (String, 30 characters ) derecho
#href (String, 17 characters ) taxonomy/term/543
#options (Array, 2 elements)

So, the print statement should show colegios and derecho, am I right?

What´s wrong with it?

UPDATE

This is the output I get with dpm($node);

(object) array(
  'vid' => '5178',
  'uid' => '1',
  'title' => 'PROYECTO',
  'log' => '',
  'status' => '1',
  'comment' => '2',
  'promote' => '0',
  'sticky' => '0',
  'nid' => '155',
  'type' => 'jornadas',
  'language' => 'und',
  'created' => '1095048000',
  'changed' => '1360589684',
  'tnid' => '0',
  'translate' => '0',
  'revision_timestamp' => '1360589684',
  'revision_uid' => '1',
  'taxonomy_vocabulary_4' => array(),
  'taxonomy_vocabulary_6' => array(
    'und' => array(
      array(
        'tid' => '33',
        'taxonomy_term' => (object) array(
            'tid' => '33',
            'vid' => '6',
            'name' => 'Jornadas Gratuitas',
            'description' => '',
            'format' => NULL,
            'weight' => '0',
            'vocabulary_machine_name' => 'vocabulary_6',
          ),
      ),
    ),
  ),
  'taxonomy_vocabulary_7' => array(
    'und' => array(
      array(
        'tid' => '40',
        'taxonomy_term' => (object) array(
            'tid' => '40',
            'vid' => '7',
            'name' => 'Para PH',
            'description' => '',
            'format' => NULL,
            'weight' => '-10',
            'vocabulary_machine_name' => 'vocabulary_7',
          ),
      ),
    ),
  ),
  'taxonomy_vocabulary_11' => array(
    'und' => array(
      array(
        'tid' => '262',
        'taxonomy_term' => (object) array(
            'tid' => '262',
            'vid' => '11',
            'name' => 'colegios',
            'description' => '',
            'format' => NULL,
            'weight' => '0',
            'vocabulary_machine_name' => 'vocabulary_11',
          ),
      ),
      array(
        'tid' => '543',
        'taxonomy_term' => (object) array(
            'tid' => '543',
            'vid' => '11',
            'name' => 'derecho',
            'description' => '',
            'format' => NULL,
            'weight' => '0',
            'vocabulary_machine_name' => 'vocabulary_11',
          ),
      ),
    ),
  ),
  'body' => array(
    'und' => array(
      array(
        'value' => "

...

  • you should get your print using your first command, but as you can see taxonomy_vocabulary_11 has 17 elements, dig deeper like <?php print render($content['taxonomy_vocabulary_11']['und']['0']); ?> or sth like that – Sohail Feb 11 '13 at 18:10
  • Thanks, but that would mean that they all have the same term, I need a statement to print "all terms", even if it has 5 or more. – Rosamunda Feb 11 '13 at 19:00
  • ie. I could use <?php print render($content['taxonomy_vocabulary_11'][0]['#title']); ?>, but if the node has 5 tags associated to that particular vocab I should print [1]['#title'], [2]['#title'], etc? It doesn´t make any sense. – Rosamunda Feb 11 '13 at 19:09
1

prior to your comment you should use foreach it would be sth like this:"

<?php foreach ($content->taxonomy_vocabulary_11 as $key => $value): $terms = $value['#title']; ?>
    <span class="all-terms"><?php print ucwords($terms); ?></span>
 <?php endforeach?>
  • Thanks for your reply! But I´ve tried that and I get this nasty error "Notice: Trying to get property of non-object". – Rosamunda Feb 11 '13 at 22:50
  • I´ve replaced $content to $node, but I get another error "Notice: Trying to get property of non-object" – Rosamunda Feb 11 '13 at 23:28
  • you are rendering your theme the wrong way, and its a notice, not very nasty error, try dpm($node) and paste the output here so we can take a look – Sohail Feb 12 '13 at 10:01
  • Thanks for your comment. As it didn´t printed out what I wanted, it looked nasty to me :) I´ll update the question with the information. THANKS! – Rosamunda Feb 12 '13 at 12:59
  • take a look at this: stackoverflow.com/questions/8617554/… – Sohail Feb 12 '13 at 17:07

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.