Jump to content

How to get specific row of a repeater?


Jon
 Share

Recommended Posts

Hello All,

I am just wondering what is the best way to get a specific row of a repeater. I have a list of courses stored in a repeater. On my parent page i will list all the courses/dates and when. What I planned on doing was getting the ID of the row in a GET and then showing the content of the repeater row on the booking page. Can this be done without using a foreach?

Cheers

Jon

Link to comment
Share on other sites

If I understand right, you will be outputting all the repeaters on the parent page and each of these will include a link to the booking page.

Because a repeater item is a page you can use the page ID to identify it. So on your parent page...

foreach($page->my_repeater as $repeater_item) {
    $link = "/booking/?id={$repeater_item->id}";
    // output the markup for your repeater item including the link
}

And on the booking page...

$id = $sanitizer->int($input->get('id'));
$repeater_item = $pages($id);
if($repeater_item->id) {
    // output the markup for your repeater item
}

You could use a URL segment instead of a GET variable if you prefer.

  • Like 1
Link to comment
Share on other sites

Hey guys thanks for the input. I went with the option from Robin just reading up on URL segments now as that looks like a even better option.

 

Cheers

 

Jon

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