node_images node object variable template is a String but suppose to be an Array

Ectar - October 26, 2009 - 04:06
Project:Content Templates (Contemplate)
Version:6.x-0.10
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active
Description

Trying to get to node Images images URL and other object fields. Here is my template:

<table width="100%" border="0">
  <tr>
    <td  width=100px><?php print $node->node_images["1"]->filepath; ?></td>
    <td><?php print $node->teaser ?></td>
  </tr>
</table>

And I see that in php code it displays proper UR, but here in contemplate- no! So what I'm dooing wrong?
BTW in the list of variables - I dont have anything besides "$node->node_images"

#1

zinasahib - October 28, 2009 - 21:43

Hello!

I came across your problem by coincidence, I just solved a similar one in my system today ;-)
My requirement was more, so I edited my code below to suit your case:

**********************************************************************

<table border="0" cellpadding="2" cellspacing="0" align="top" width="90%">
<tr></tr>
<tr></tr>
</table>
<table border="0" cellpadding="2" cellspacing="0" align="top" width="90%">
<tr>
<td>
<?php
for ($i=0; $i<=count ($node->node_images); $i++)
{
  print
$node->node_images[$i]['filepath'];
}
?>

</td>
</tr>
</table>

*************************************************************************

What this does is that it loops your "array" and prints out all the filepaths.

This is where you need to post this code:

Admin>content types> page (for example, or whichever you are using)> Page>edit> Template>
click on Teaser, check the "Affect teaser output" and page the code there.
Remember to save, then try it out.

Hope this helps!

#2

Ectar - November 11, 2009 - 20:32

Doesn't work for me.
I getting empty table in Teaser... like that:

<table align="top" border="0" cellpadding="2" cellspacing="0" width="90%">
<tr></tr>
<tr></tr>
</tbody></table>
<table align="top" border="0" cellpadding="2" cellspacing="0" width="90%">
<tbody><tr>
<td>
</td>
</tr>
</table>

Any Ideas? Looks like it that PHP code doesn't produce any output, that is mean that $node->node_images[$i]['filepath']; is not populated!!!
But $node->node_images shows node image in teases properly!

I have Drupal 6.11 installed.

#3

Ectar - November 11, 2009 - 20:55

I think I understand what is going on!!!!

<?php
 
print $node->node_images;
?>

Is a String not an object!!! That is why print $node->node_images[0]; will produce '<' and print $node->node_images[1]; - will produce 'a'...just because print $node->node_images = ""

So conclusion is:

<?php
 
print $node->node_images;
?>

Is not real PHP code... this is just a placeholder with will be replaces by some HTML!!! Or I'm missing something?

#4

Ectar - November 11, 2009 - 20:59
Title:Help please with node images» node_images node object variable template is a String but suppose to be an Array
Component:Miscellaneous» Code
Category:support request» bug report

Upgrading this to bug.
Because:

$node->node_images; suppose to be an Array not a String.

It is works lie array if I add PHP code: $node->node_image for testing in page.tpl.php though.

#5

zinasahib - November 12, 2009 - 22:31

Hi again,
It looks like "node_images" is not the proper variable to use, because apparently its not an array, which is what we want.
I suggest you go through the list of variables your system gives you, and see if:
1. node_image is defined there as an array or string;
2. what is the correct variable to use?

You can look into it through:
Admin>content types> page (for example, or whichever you are using)> Page>edit> Template>
click on Teaser, click on Teaser variables and go through that list.
In my case, it clearly says: $node->field_pictures[0] array
Which is the one I use.
Look for something similar. (Note: field_pictures is what I defined)
Let me know how it goes..

 
 

Drupal is a registered trademark of Dries Buytaert.