Jump to content

Repeater Field with Page Reference


disall2000
 Share

Recommended Posts

I'm very new to both Processwire and PHP so bare with me. Now I've set up everything in the different Fields, Pages and Templates. In one of the templates I have created a Repeater Field containing one Field that is a Page Reference and another Field that is a Text Field.

Now I've tried both

foreach ($page->template->fieldgroup as $f) {
    echo $f->name . "<br>";
}

and

<?php echo $page->get("myfieldgroup"); ?>

Here I get the ID's from the Page Reference but nothing from the Text Field. The first example gave me nothing at all.
So how do fetch these results?

Link to comment
Share on other sites

You can access a repeater field directly by its name, no need to use $page->template..

So, to get a title field inside a repeater, you just need:

$repeater = $page->your_repeater_name;

foreach( $repeater as $rep ) {
	echo $rep->text_field_name;
	echo $rep->page_reference_field_name->title; //output the title of the page that's referenced
}

 

Edited by Sergio
submitted without code
  • Like 1
Link to comment
Share on other sites

You treat the repeater like any other field.

<?php

foreach($page->repeaterfield as $rep) {
  echo "<p>{$rep->pagereffield->title}</p>\n";
  echo "<p>{$rep->textfield}</p>\n";
}

$page->repeaterfield (like $page->get("myfieldgroup") in your example) will get you the repeater field itself, and in string context, return the IDs of its individual repeater elements.

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