Jump to content

echo an id from repeater


Paschalis
 Share

Recommended Posts

Dear friends,

i am a newbe but very glad to join the team...

My question is ...

from a page www.pagename.com/portfolio/1091 i want to echo a repeater's title, images etc. The 1091 is the repeater's id

i tried the one below:

$repeater_id = filter_var($input->urlSegment(1), FILTER_SANITIZE_NUMBER_INT);
$repeater = $fields->get($repeater_id);
echo $repeater->title;
 
But Nothing happens.
 
Any idea?
 
 
Link to comment
Share on other sites

Welcome to the forum Paschalis.

This is not the usual way of getting repeater Items, but since you know the ID and repeaters are pages just like any other page, it's as easy as:

$pages->get($repeater_id)->title
  • Like 3
Link to comment
Share on other sites

Welcome to the forum Paschalis.

This is not the usual way of getting repeater Items, but since you know the ID and repeaters are pages just like any other page, it's as easy as:

$pages->get($repeater_id)->title

Thank you so much ... i didn't even know that the repeaters are pages ... i thought they were fields ... Thanks a lot

Link to comment
Share on other sites

i thought they were fields ... Thanks a lot

Fields in ProcessWire as in '$fields' are $Field objects. It is not where you find your data. The data in ProcessWire is saved together with the page ID. So to get data from a field you have to ask the 'page' for it, like $page->title or equivalent $page->get('title').

Link to comment
Share on other sites

Like Martijn said, repeater is a field, but it's items are pages. So, a repeater field is not more than a reference to a group of pages. You can find these pages hidden under your "admin" page, and can be called and treated as any other pages. You usually don't have to call them directly, like we just did with the ID, but instead, you call them through the repeater field,
 
either by looping the field:

foreach($page->repeater as $item) {
    echo $item->title;
}

or by using the pageArray methods to call one of it's items:

echo $page->repeater->first()->title;
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

×
×
  • Create New...