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.
By Rick Hood on
I want to grab be able pull out images attached to nodes and put them where I like in page.tpl.php.
I thought that this code placed in page.tpl.php would do it, but it doesn't.
<?php print $node -> content['image_attach'][‘#value’]; ?>
While I'm at it, this doesn't work either, just to simply pull the title out:
<?php print $node -> content['title'][‘#value’]; ?>
But this does work:
<?php print $title ?>
What am I doing wrong? I'm sure this is a dumb one.
Comments
That's a bit hazy
What specifically are you trying to do with images attached to a node and what title are you trying to print out? The current node's title or something else?
If you can describe what you need more clearly then I can probably give you a code snippet.
I am trying to put images
I am trying to put images attached to a node where I want to in the page.
The devel module tells me its there in content (see below) but I don't know how to access it.
To get you started
Obviously I don't know all the variables that exist in the string you're trying to print but I'm a fan of taking a more direct route. This will just look for attached images and create based on that. Not sure where each image will be linking too, but you could always use the description field to populate that instead of the title. Hopefully this will at least get you started.
Great work =D>
Amazing work ,
i appreciate this approach even. Though in drupal everything is done via module/hooks etc..
but sometimes i am realy stuck to using this extended APIS and opt to code manually as u did.
great work done .
Only one picture...
Placeing Your code in page.tpl.php shows up only one picture of the attached two pictures. Funny, but
print_r($node->files)
orprint sizeof($node->files)
shows, that there are eg. two files, butforeach($node->files as $files) { .... }
prints up only one, the second one... What did I wrong?Thx a lot.
image attach filepath
Anyone have any luck finding the path for image attach?
It seems that my attached images are not listed in
$node->files
.Also, great work on your code above. THANKS.
I realized what I was doing wrong.
This works fine:
<?php print $node -> content['image_attach'][‘#value’]; ?>
but you have to put it in the node tpl file, not the page tlp file! Dumb.
Keep it simple.
----
Darly
printing attached image doesn't work for me
Hi all,
I've been reading this article and tried to print an attached image but it doesn't display anything.
Here is my original post which seems to going nowhere.
http://drupal.org/node/215081
print $node -> content['image_attach'][‘#value’];
Doesn't work for me.
Any help?
Put it in node.tpl.php
Are you putting this code in your page.tpl.php file? If so, thats the problem. It goes in node.tpl.php. Its confusing because there is a $content variable in both places - but they are different.
This only sorta works for me...
I had to change the tick marks around #value, and then it worked - kind of...
I don't see the image when I look at the page. However, when I look at the code with firebug, the img src is there. But in the HTML it is grayed out and does not display. I can't give a link to the site as it is for a client and is pw protected. The whole div is grayed out, actually.
Everything after
tag is gray in firebug.
doh!
the image-attach-body class had a display:none on it...
SOLVED! lol
Wow, I spent *ages* trying to figure this out
Mate, this may sound simple, but I spent *ages* trying to figure this out.
I read a million different pages but finally here's the answer.
Thanks mate
Theres an easier way to do this
Why don't you use the Contemplate module? You can get the exact code to print all the variables that the node has.