Jump to content


Photo

Repeater Field Question

repeater field

  • Please log in to reply
9 replies to this topic

#1 bizzzel

bizzzel

    Newbie

  • Members
  • Pip
  • 4 posts
  • 2

Posted 01 May 2012 - 02:58 PM

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

#2 diogo

diogo

    Hero Member

  • Moderators
  • 2,007 posts
  • 1081

  • LocationPorto, Portugal

Posted 01 May 2012 - 04:56 PM

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


#3 Soma

Soma

    Hero Member

  • Moderators
  • 3,194 posts
  • 1750

  • LocationSH, Switzerland

Posted 02 May 2012 - 05:58 AM

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.

@somartist | modules created | support me, flattr my work flattr.com


#4 diogo

diogo

    Hero Member

  • Moderators
  • 2,007 posts
  • 1081

  • LocationPorto, Portugal

Posted 02 May 2012 - 07:23 AM

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

#5 bizzzel

bizzzel

    Newbie

  • Members
  • Pip
  • 4 posts
  • 2

Posted 03 May 2012 - 10:04 AM

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

#6 Soma

Soma

    Hero Member

  • Moderators
  • 3,194 posts
  • 1750

  • LocationSH, Switzerland

Posted 03 May 2012 - 10:13 AM

If you would show us some code, we would be able to help much easier. :)

@somartist | modules created | support me, flattr my work flattr.com


#7 apeisa

apeisa

    Hero Member

  • Moderators
  • 2,526 posts
  • 854

  • LocationVihti, Finland

Posted 03 May 2012 - 10:17 AM

Just add first() before ->url. I guess you have an array instead of single image.

#8 diogo

diogo

    Hero Member

  • Moderators
  • 2,007 posts
  • 1081

  • LocationPorto, Portugal

Posted 03 May 2012 - 10:30 AM

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


#9 bizzzel

bizzzel

    Newbie

  • Members
  • Pip
  • 4 posts
  • 2

Posted 03 May 2012 - 10:30 AM

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

#10 bizzzel

bizzzel

    Newbie

  • Members
  • Pip
  • 4 posts
  • 2

Posted 03 May 2012 - 10:37 AM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users