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"

Comments

zinasahib’s picture

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!

Ectar’s picture

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.

Ectar’s picture

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?

Ectar’s picture

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 » bug

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.

zinasahib’s picture

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..

Ectar’s picture

zinasahib, thank you for you input but I don't have anything else related to node_images rather then $node->node_images

Where do you define that 'field_pictures'?

zinasahib’s picture

Hi Ectar,
Hope you are well.
To answer your question; I went to: Admin>Content Management>Content Type>
Select the one you want to add images too (in my case it is Page, so go to 'edit template')

Under "Manage fields" you can add this field. My settings are:
Label: p_gallery
name: field_pictures
Field type: File
Widget type: Image

Ectar’s picture

Wow ! I don't have all that. What kind of Drupal you have, and what version of node_images?

I suppose you meant Admin>Content Management>Content Template> not 'Content Type'....?!