Jump to content

loading image from field named logo


Galaxy
 Share

Recommended Posts

I've created a field called "logo" and the type is "image" - and there may be multiple files uploaded via this field.

How do I use this in a template?

I've looked at http://processwire.com/api/fieldtypes/images/ but still can't work it out.

Galaxy,

What don't you get? Do you want to output a single image? Random images?  Is it working for you now?

Link to comment
Share on other sites

I have different image types you might say. With each page I can upload a "logo" and a set of "standard" images. Hence, I have a field called "logo" where I upload the respective logo/s for that page. I also have another field called "images" (that handles images that aren't logos)

On viewing the page I want to load the logo images only into a specific place (css handles the placement of course) but I need to just grab the logo image/s - not any of the "standard" type images (they load into other parts of the page).

I want to target and load only the image that is uploaded view a field I've called "logo".

Link to comment
Share on other sites

using

foreach($page->images as $image) {
                echo "<img src='$image->url' class='thumb'>";
                        }
 

loads the files that I've uploaded via the image type field named "images"

Then for loading the logo files I've tried changing $page->images to $page->logo but that doesn't work for loading the image field "logo"

Link to comment
Share on other sites

If you allow multiple images with your 'logo' field, then the code must work - assuming you have at least one image uploaded on the page viewing.

I'd try again :)

If it does not work: Enable debug mode in /site/config.php ($config->debug = true) and check for any errors.

Btw when you allow multiple images, why not calling your field 'logos' - would be more logical

  • Like 2
Link to comment
Share on other sites

Thanks Wanze,

in debug mode

<?php

                foreach($page->logo as $image) {
                echo "<img src='$image->url' class='thumb'>";
                        }
                ?>
 

The message is Notice: Trying to get property of non-object in /var/www/vhosts/acumulus.co.nz/subdomains/legacytrust/httpdocs/site/templates/tabs.inc on line 20

line 20 is echo "<img src='$image->url' class='thumb'>";

Link to comment
Share on other sites

Is the field setup for multiple images? If it is try:

echo "<img src='{$image->first()->url}' class='thumb'>";

FYI above didn't work for me but the following did once I made sure it was set to handle multiple images

echo "<img src='{$image->url}' class='thumb'>";
 

and without the { } it also worked.

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