Jump to content

Recommended Posts

Posted

I added the repeater field to my page.

In the php template I added : <?php echo $page->my-repeater-area; ?>

When I display the page in a browser - it's showing "1011", not the text and images from what I input in the admin area.

What am I missing here?

(The sub fields in the for each "my-repeater-area" are: building-description, building-image, and building-text.)

Thanks in advanced:

Ben

Posted

Welcome to the forum Ben!

You have to iterate over the repeater, and output each field:

foreach($page->my_repeater-area as $building)
{
 echo "<p>{$building->building_description}</p>";
 echo "<img src='{$building->building_image->url}' alt='{$building->building_image->description}' />";
 echo "<p>{$building->building_text}</p>";
}
  • Like 2
Posted

I don't know if you know that variables/namings in php can't contain a dash "-". So also this is true to a field name in PW.

So things like:

$page->my-repeater-area

doesn't work.

I'm sure you know it, but typed it wrong in your post.

  • Like 1
Posted

Thanks Soma! Edited the post so it doesn't contain wrong information. I'm glad you are sure I know it, but actually, as I'm really new to PHP (or any programming language, by the way), those things are not that present in my mind...

Posted

Thanks for the info!!

One issue - Everything works expect the image doesn't display. I checked the source code and the php is trying to show it, but the URL is wrong. Its showing the 1011 again:

<img alt="" src="/site/assets/files/1011/">

Should be something like:

<img alt="" src="/site/assets/files/1011/my_imageFluffyCat.jpg/">

Posted

Or, iterate over all images:

foreach($page->my_repeater-area as $building)
{
 echo "<p>{$building->building_description}</p>";
 echo "<p>{$building->building_text}</p>";
 foreach($building->building_image as $img)
 {
   echo "<img src='{$img->url}' alt='{$img->description}' />";
 }
}
  • Like 1
Posted

foreach($page->buildingsRepeat as $building)

{

echo "<p>{$building->buildingInfo}</p>";

echo "<img src='{$building->buildingImage->url}' alt='{$building->buildingImage->description}' />";

echo "<p>{$building->body}</p>";

}

Here is the code. Yes looking to display single image. (Sorry I changed the names from original (removed "-"))

Posted

Diogo -

Your last post worked perfectly!!! Thank You so much - very new to ProcessWire (looking for WordPress replacement) and so far loving me sum ProcessWire.

  • Like 2

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
×
×
  • Create New...