because i always forget [or sometimes didnae know in the first place], what variables are available, and what values they hold, when overriding a drupal node.tpl file.
since drupal tends to hold all the info for constructing a page inside nested arrays... inside nested arrays... inside nested arrays... etc. etc. you need to dig down quite a few levels before you actually start getting to the meat and potatoes.
stick this code in the top of one of your node_xxxxx.tpl.php files and it will dig four nested arrays deep and print out what it finds in a logical format:
arrayname["nested arrayname"]["nested arrayname"]["nested arrayname"] = VALUE
any arrays which dinnae go four levels deep will return a "Invalid argument supplied for foreach().." error and you'll have to not dig so deep to find their values. any values hidden deeper than four nested levels will just return as ARRAY and you'll need to dig even deeper!
when you get the value you're after, you generally use it in a node template by using everything after the 'node' bit. so if my value was at:
field_productimage["field"]["#node"]["title"] = some product name
i'd add it into my drupal node template using something like:
<div> $node->title </div>
OK it ain't very elegant and it's a bit of a clunker, as you need to hack the code about for different levels of digging, but it helps me find the crap i'm looking for, so it'll do me 'til i write sommit better.
- foreach($node->content as $outerarray=>$outerarrayvalue)
- foreach($outerarrayvalue as $innerarray=>$innerarrayvalue)
- foreach($innerarrayvalue as $centrearray=>$centrearrayvalue)
- foreach($centrearrayvalue as $key => $value)
- echo("<em>".$outerarray."[\"".$innerarray."\"][\"".$centrearray."\"][\"".$key."\"] = </em><b>".$value."</b><br />");
You need to login to post a comment.