Contentful logo

Contentful Community

How do I loop different sections inside a landing page with php

Using the php SDK, I would like to get all the content for a landing page, this will include sections with different content types / components.

eg.

Section 1 - hero
Section 2 - article
Section 3 - image

Q. How do I loop through and get the linked section content.

If an entry contains a link to an asset or another entry, the SDK will automatically load it.

How exactly do I break into these values?

<?php
$query = new \Contentful\Delivery\Query();
$query->setContentType('page_landing')
->where("fields.urlHandle[match]", $slug);

$products = $client->getEntries($query);

foreach ($products as $product) {

echo $product['name'];

// Example of what I am trying to achieve
    if($product['sections']['id']=='hero'){
      $title= $product['sections']['hero']['title'];
    } 
    if($product['sections']['id']=='article'){
      $text = $product['sections']['article']['text'];
    } 
}
?>