Jump to content

image does not show up


helmut2509
 Share

Recommended Posts

I have a page on which I want to display an image.
So I created a field 'images' with field type 'image' and added it to the page template.
Maximum files set to 3.
Image was uploaded and properly stored in filesystem and database.
In the template file I have this command

img src="<?php echo $page->images[0]->url ?>..
 

..
but the image does not show up.
The URL generated was just "/ProcessWire/" (root directory of the app).
Strange thing is that
echo $page->images->url... (shouldn't it be an array?)
produces  "/ProcessWire/site/assets/files/1/" ...which is better than the former one,
but still filename is missing.

any suggestions?

Link to comment
Share on other sites

You sort of answered your question ... :-)...arrays...http://processwire.com/api/fieldtypes/images/

Hint..."foreach...." ;-)

...Edit...am too slow...Martijn beat me to it :-)

So it is not possible to get the image url by "$page->images[0]->url" ?

foreach only makes sense if all images are handled in the same way.

But what if you want to handle the images individually?

Link to comment
Share on other sites

It's not an regular array but a WireArray.

You can use all WireArray methods that are listed on the cheatsheet.

$page->images->first->url;
$page->images->last->url;
$page->images->eq(3)->url;
...

thanks Soma, I will try this in the evening.

But this is a feature which should also be mentioned in the image-fieldtype documentation...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...