Reezal AQ Posted March 5, 2017 Share Posted March 5, 2017 Hello, I have a Repeater of clients testimonial on main.php which I want to appear on 4 other pages. If I go to Setup >> Field >> Repeater >> Action and select the pages I want the Repeater to appear, I have re-enter all testimonial details in new Repeater field created on the other 4 pages. I think I did it wrong. Is there a smarter way to do this without repeating ? Link to comment Share on other sites More sharing options...
adrian Posted March 5, 2017 Share Posted March 5, 2017 I think you might be confusing templates and pages. main.php would be template file that controls the output of pages with the "main" template, but usually main.php is used as based template that is included or modified by other templates. That aside, you need to get the repeater content from the page where it exists, so something like this: $p = $pages->get(selector to get page where repeater content is); foreach($p->repeaterfield as $repeateritem) { //usual repeater output } 1 Link to comment Share on other sites More sharing options...
Reezal AQ Posted March 5, 2017 Author Share Posted March 5, 2017 18 minutes ago, adrian said: I think you might be confusing templates and pages. main.php would be template file that controls the output of pages with the "main" template, but usually main.php is used as based template that is included or modified by other templates. That aside, you need to get the repeater content from the page where it exists, so something like this: $p = $pages->get(selector to get page where repeater content is); foreach($p->repeaterfield as $repeateritem) { //usual repeater output } Like this ? <div class="carousel-inner" role="listbox"> <?php $p = $pages->get($TestimonialsRepeater); $x = 0; foreach($p->TestimonialsRepeater as $TestimonialsRepeaters) : $class = ($x === 0) ? "active" : ""; ?> <div class="item <?= $class ?>"> <blockquote> <ul> <li><img src="<?=$TestimonialsRepeaters->CustomersImage->first()->url ?>" class=" img-responsive" alt=""/></li> <li class="name"><?=$TestimonialsRepeaters->CustomersName ?></li> </ul> <?=$TestimonialsRepeaters->CustomersComment ?> </blockquote> </div> <?php $x++; endforeach;?> </div> I placed it in main/about-us page but didn't work. Link to comment Share on other sites More sharing options...
adrian Posted March 5, 2017 Share Posted March 5, 2017 I have no idea what you have initially defined $TestimonialsRepeater to be. What you want there is a selector to get the page. For example, if the repeater content was on the homepage, then you could do: $p = $pages->get("/'"); Link to comment Share on other sites More sharing options...
Reezal AQ Posted March 5, 2017 Author Share Posted March 5, 2017 Okay, I got it ! Forgot to put <?php $p = $pages->get("/main/"); Thanks Adrian! 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now