1

Tried to print variables in view template, but the print-out is huge,deep-nested and recursive... crazy thing... Just can't drill down to the rendered_fields array, which seems to be just what I need. Is there any comprehendable reference anywhere?

3 Answers 3

2

What I usually do when I need to inspect a views variable, that often can be as complex as you describe is to use dpm. Dpm can't always show all of the items since the information is repeated. But then you can dpm the specific parts you need.

So you often start doing dpm($view); but end up using dpm($view->displays...); to get what you need. Using a reference might be a bit overkill since the view varisble is dymanic, but after doing it a while you start figuring out where you can find stuff. The names is pretty selfexplanatory.

4
  • That sounds as a solution... but when I do dpm($view); nothing gets printed out?.. Any special treatment needed?
    – jayarjo
    Commented Jun 27, 2011 at 17:49
  • Found out that dpm uses kprint_r() so I just used it directly - awesome! Still not sure why dpm didn't work though... and I still wouldn't mind to see a good reference about what all these fields are for :|
    – jayarjo
    Commented Jun 27, 2011 at 18:06
  • 1
    If you aren't logged in as a user with appropriate permissions, dpm() doesn't display.
    – mpdonadio
    Commented Jun 27, 2011 at 18:08
  • I thought of this, but I thought I was logged in as admin. Ok I will look into this, thanks.
    – jayarjo
    Commented Jun 27, 2011 at 18:09
2

A little underground byt you have

<?php
dpm(get_defined_vars());
?>
1

There is a row template that can be found in the Views theme section. It iterates through each field and then wraps it in markup. Another way to do it is to test if a field is empty then print it. Here is an example from a template I just created.

  <?php if (!empty($fields['field_dicussion_category']->content)): ?>
    <div class="category"><span class="field-label">Category: </span><?php print $fields['field_dicussion_category']->content ?></div>
  <?php endif; ?>

What you can do is a dsm($fields) which will show you the available options.

I don't know too much about the Eclipse IDE or ClientXDebug but I use PhpED to work with code in Drupal. It only costs a couple hundred bucks and is completely worth it. I can put a breakpoint in any part of the code and the IDE will stop the page load and show all the variables. Better yet I can step through and see how the variables change.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.