nexuspolaris Posted November 20, 2020 Share Posted November 20, 2020 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. Link to comment Share on other sites More sharing options...
LostKobrakai Posted November 20, 2020 Share Posted November 20, 2020 find does return a pagearray, not a single page. You need findOne or get. Link to comment Share on other sites More sharing options...
nexuspolaris Posted November 20, 2020 Author Share Posted November 20, 2020 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"); Link to comment Share on other sites More sharing options...
LostKobrakai Posted November 20, 2020 Share Posted November 20, 2020 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); Link to comment Share on other sites More sharing options...
nexuspolaris Posted November 20, 2020 Author Share Posted November 20, 2020 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! 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