Jump to content

Recommended Posts

Posted

Hello,

I made a 'Services' page where I listed some certain services. I'd like to display some of them service by title, featured image and summary on home page. 

I try to get the 'service_box' repeater field's fields in home page template, but it doesn't work:

$services = $pages->find("template=services");
$service_box = $services->get("service_box");

foreach($service_box as $service) {

    $content .= "<div class='service'>";
    $content .= "   <div class='service-body'>";
    $content .= "    <h4>{$service->subtitle}</h4> ";
    $content .= "    <summary>{$service->body}</summary>";
    $content .= "  </div>";
    $content .= " </div>";
       
}

Thanks for help.

Posted
9 minutes ago, LostKobrakai said:

find does return a pagearray, not a single page. You need findOne or get.

Thanks, it worked this way:

$services = $pages->get("template=services");
$service_box = $services->get("service_box");

But how to limit the services number on home page if I want to display only the first 3 item? This dropped error:

$service_box = $services->get("service_box, limit=3");

 

Posted

Selectors are only for fetching pages, not field values (even though tech. the field value here is pages). You can use this:
 

$first_three = $services->get("service_box")->slice(0, 3);

 

Posted
2 minutes ago, LostKobrakai said:

Selectors are only for fetching pages, not field values (even though tech. the field value here is pages). You can use this:
 


$first_three = $services->get("service_box")->slice(0, 3);

 

Thanks, I appreciate your fast answer!

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...