Jump to content

Repeater Image not showing


sisterlarao
 Share

Recommended Posts

Hey,
 
I am a processwire newbie. I found the module "repeater fields". Everything is working finde. My titles are showing - but not the images.

My code: I already tried different variables, but the images are not showing (attachement image).

 

div class="container-fluid"> 
    	<div class="row"> 
         <? foreach ($page->columns as $col):?>

            <div class="col-sm-3 img-responsive">

               <a href="#"> <img src="<?php echo $col->images; ?>" /> </a>
               <div class="test"><a href="#"><?=$col->title; ?> </a></div> 
            </div>
          <? endforeach; ?>

        </div>
    </div>

Anyone an idea?

Thank you!

post-3463-0-34988000-1433155860_thumb.pn

Link to comment
Share on other sites

<a href="#"> <img src="<?php echo $col->images; ?>" /> </a>

should be something like
<a href="#"> <img src="<?php echo $col->image->url; ?>" /> </a>

attention: you can set up image fields to have ONE ore MULTIPLE images in it. if you set the max number to ONE, then the example above will work. if you set it to multiple files, you would need something like this:

foreach($col->images as $img) {
    echo '<a href="#"> <img src="' . $img->url . '" /> </a>';
}

welcome to processwire and the forum ;) happy processwiring!

  • Like 1
Link to comment
Share on other sites

Welcome to processwire!

No problem you should read about the difference that your title field is a "field" and your image field is a "array" of images/files...

so try with:

div class="container-fluid"> 
    	<div class="row"> 
         <? foreach ($page->columns as $col):?>

            <div class="col-sm-3 img-responsive">
// get the very first image from images list since image field is accepting multiple images (unless you change the value of `Maximum files allowed` under Fields > images > Details tab > Maximum files allowed).
               <a href="#"> <img src="<?php echo $col->images->first(); ?>" /> </a>
               <div class="test"><a href="#"><?=$col->title; ?> </a></div> 
            </div>
          <? endforeach; ?>

        </div>
    </div>

edit: BernhardB beat me....;)

Edited by mr-fan
  • Like 1
Link to comment
Share on other sites

if you are new i would suggest to keep everything as simple as possible: so start with a single image-field and a SINGLE image to get familiar with it. note that "images" and "image" in the code above assumes that your field's name is set to those values.

what errors do you get?

Link to comment
Share on other sites

ok found the missing thing...deeper look in your html shows:

<a href="#"> <img src="unfallservice.png"> </a>

so the imagename is there....not the path/url...so it was wrong example from me...since i load the image always in a var like:

//get the first image from the array of the repeater field
$myimage = $col->images->first();

and then use it like:

//use the $myimage var to call all needed things like url, name, description...
<a href="#"> <img src="<?php echo $myimage->url; ?>" alt="<?php echo $myimage->description; ?>" /> </a>

you can set the size, too with this API calls have a good read here:

https://processwire.com/api/fieldtypes/images/

there is my example, too

for a fast look you could quick change:

<a href="#"> <img src="<?php echo $col->images->first(); ?>" /> </a>

//to

<a href="#"> <img src="<?php echo $col->images->first()->url; ?>" /> </a>

best regards mr-fan

  • Like 3
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...