Jump to content

Recommended Posts

Posted

I tend to set up a 'Settings" page with a heaps of fields I can use anywhere. Something like this might work:

<img src='"  .  $pages->get('/settings/')->images->eq(0)->url  .  "'/>

or simply:

<img src='"  .  $page->images->eq(0)->url  .  "'/>
Posted

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

Posted

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"

Posted

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
Posted

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'>";

Posted

Hold on, yeah, it's working . I took a look at the field details tab "max files allowed" - it had 1. Changed to 0 and it's sweet. My bad.

Posted

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.

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
  • Recently Browsing   0 members

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