Displaying Image from Image/File Page Attribute

Permalink 2 users found helpful
I'm trying to do something that should be really simple but having a hard time doing it, probably because of my lack of PHP skill.

I have a page type that has two image/file attributes associated with it. One is for the thumbnail that is associated by the entry, to be displayed in a modified page list (handle for this is "photo_thumb") the other is a photo to be displayed in the body of the page (handle = "photo").

I need a way to grab the img URL for the chosen image but I'm not sure how to do it.

I thought I could add something like this to the page template:
<img src='<?php echo $c->getCollectionAttributeValue('photo') ?>' />


But that does not seem to work. I'm guessing that's because I need to do something more to pull the URL out of that image record, looking around I think this involves 'getFileRelativePath()'.

Can somebody help me with code that will display whatever image I pick in the file attribute in the body of the page?

Much thanks!

Jory
View Replies:
maschenborn replied on at Permalink Reply
maschenborn
Did you already find a solution?
I've the same problem and I don't want to use a block at a special position.
Jory replied on at Permalink Reply
Jory
No dice yet. I've seen some discussion of this around the forums but no definitive answer. Anyone out there have ideas on this?
ScottC replied on at Permalink Reply
ScottC
Well here is what is happening.

The file page attribute actually references a fileobject.

What you would want to do is go with:

<?php echo($c->getAttribute('attribute_handle')->getVersion()->getRelativePath());?>


This will give you a relativepath to a file which can be used as a hyperlink or part of the src attribute of an img tag.

I hope this helps you.
Jory replied on at Permalink Reply
Jory
That did it. Your a good man ScottC. Thanks for taking the time to help.
ijessup replied on at Permalink Reply
ijessup
<?php
$imgHelper = Loader::helper('image');
global $c;
if ($c->getAttribute('image')) {
   $image = $imgHelper->getThumbnail($c->getAttribute('image'), 350, 350)->src;
}
?>


The getThumbnail function will create a thumbnail within a specific boundary and spit out the url.
hursey013 replied on at Permalink Reply
hursey013
Since I am a PHP newbie, would I be correct to use the getThumbnail code you explained above and output it as something like this...
<img src='<?php echo $image ?>' />
It works fine, I just want to make sure performance wise thats the correct usage. Thanks for the great snippet!
RadiantWeb replied on at Permalink Reply
RadiantWeb
helpful stuff. thanks for posting guys.
ScottC replied on at Permalink Reply
ScottC
i'd double quote the src although i have no idea if that is necessary.
imran replied on at Permalink Reply
Hi ijessup:
Very helpful stuff you post. i have problem with getting page attributes (image), now its ok. But can you tell me the story that from where i find such nice things...

Once again thank you.