Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment #1
zinasahib CreditAttribution: zinasahib commentedHello!
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:
**********************************************************************
*************************************************************************
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!
Comment #2
Ectar CreditAttribution: Ectar commentedDoesn't work for me.
I getting empty table in Teaser... like that:
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.
Comment #3
Ectar CreditAttribution: Ectar commentedI think I understand what is going on!!!!
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:
Is not real PHP code... this is just a placeholder with will be replaces by some HTML!!! Or I'm missing something?
Comment #4
Ectar CreditAttribution: Ectar commentedUpgrading 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.
Comment #5
zinasahib CreditAttribution: zinasahib commentedHi 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..
Comment #6
Ectar CreditAttribution: Ectar commentedzinasahib, 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'?
Comment #7
zinasahib CreditAttribution: zinasahib commentedHi 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
Comment #8
Ectar CreditAttribution: Ectar commentedWow ! 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'....?!