Galaxy Posted June 18, 2013 Share Posted June 18, 2013 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. Link to comment Share on other sites More sharing options...
Marty Walker Posted June 18, 2013 Share Posted June 18, 2013 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 . "'/> Link to comment Share on other sites More sharing options...
kongondo Posted June 18, 2013 Share Posted June 18, 2013 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 More sharing options...
Galaxy Posted June 18, 2013 Author Share Posted June 18, 2013 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 More sharing options...
Galaxy Posted June 18, 2013 Author Share Posted June 18, 2013 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 More sharing options...
Wanze Posted June 18, 2013 Share Posted June 18, 2013 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 2 Link to comment Share on other sites More sharing options...
Galaxy Posted June 19, 2013 Author Share Posted June 19, 2013 I usually use "logo" as both plural and singular. Southern family I blame it on... Link to comment Share on other sites More sharing options...
Galaxy Posted June 21, 2013 Author Share Posted June 21, 2013 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 More sharing options...
Marty Walker Posted June 21, 2013 Share Posted June 21, 2013 Shouldn't it be: echo "<img src='{$image->url}' class='thumb'>"; ? Link to comment Share on other sites More sharing options...
Galaxy Posted June 21, 2013 Author Share Posted June 21, 2013 Nah, that throws up the same error Marty. Link to comment Share on other sites More sharing options...
Marty Walker Posted June 21, 2013 Share Posted June 21, 2013 Is the field setup for multiple images? If it is try: echo "<img src='{$image->first()->url}' class='thumb'>"; Link to comment Share on other sites More sharing options...
Galaxy Posted June 21, 2013 Author Share Posted June 21, 2013 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. Link to comment Share on other sites More sharing options...
Galaxy Posted June 21, 2013 Author Share Posted June 21, 2013 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now