Jump to content

Share Repeater Feild on other pages


Reezal AQ
 Share

Recommended Posts

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

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 1
Link to comment
Share on other sites

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

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

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