i have a json file im trying to render in yii2 view. i load it via the controller and it works. but displaying the content of all three levels
treating them each as sections.

{
  "top_level": [
    {
      "level_one": {
        "title": "Welcome to Our...",
        "content": [
          "Welcome to the..",
          "Exquisite works of talented artists from various disciplines...",
          "By leveraging our...",
          "Discover new treasure..."
        ]
      }
    },
    {
      "level_one": {
        "title": "General Information",
        "content": [
          {
            "level_two": {
              "title": "About Us",
              "content": [
                "Highlighting the exquisite works...",
                "Art enthusiasts to explore...",
                "Committed to bringing the best of..."
              ]
            }
          },
          {
            "level_two": {
              "title": "Where are we located?",
              "content": [
                "Our operation is located at..."
              ]
            }
          },
          {
            "level_two": {
              "title": "How can I contact us?",
              "content": [
                "You can reach us via email..."
              ]
            }
          },
          {
            "level_two": {
              "title": "Viewing",
              "content": [
                "Unique opportunity to view..."
              ]
            }
          },
          {
            "level_two": {
              "title": "Are private viewings available?",
              "content": [
                "Online private viewings can be arranged..."
              ]
            }
          }
        ]
      }
    },
    {
      "level_one": {
        "title": "Events",
        "content": [
          "We regularly update our events..."
        ]
      }
    },
    {
      "level_one": {
        "title": "Sales",
        "content": [
          {
            "level_two": {
              "title": "How can I purchase?",
              "content": [
                "Browse our collection..."
              ]
            }
          },
          {
            "level_two": {
              "title": "Return Policy",
              "content": [
                "All sales are final."
              ]
            }
          },
          {
            "level_two": {
              "title": "Shipping",
              "content": [
                {
                  "level_three": {
                    "title": "Domestic Shipping",
                    "content": [
                      {
                        "title": "Shipping Methods and Costs",
                        "content": [
                          "We offer multiple shipping options..."
                        ]
                      },
                      {
                        "title": "Processing Time",
                        "content": [
                          "Processed within 5-7 business days..."
                        ]
                      },
                      {
                        "title": "Delivery Time",
                        "content": [
                          "Shipped within 5-7 business days..."
                        ]
                      }
                    ]
                  }
                },
                {
                  "level_three": {
                    "title": "International Shipping",
                    "content": [
                      {
                        "title": "Availability",
                        "content": [
                          "Shipping costs and delivery times vary..."
                        ]
                      },
                      {
                        "title": "Duties",
                        "content": [
                          "Potential tariffs may apply."
                        ]
                      },
                      {
                        "title": "Delivery Time",
                        "content": [
                          "Delivery times vary by destination."
                        ]
                      }
                    ]
                  }
                }
              ]
            }
          },
          {
            "level_two": {
              "title": "Packaging",
              "content": [
                {
                  "title": "Artwork Protection",
                  "content": [
                    "All items are securely packaged..."
                  ]
                },
                {
                  "title": "Special Handling",
                  "content": [
                    "Our team will contact you for special requirements..."
                  ]
                }
              ]
            }
          },
          {
            "level_two": {
              "title": "Tracking and Notifications",
              "content": [
                {
                  "title": "Order Confirmation",
                  "content": [
                    "You will receive an order confirmation email."
                  ]
                },
                {
                  "title": "Shipping Confirmation",
                  "content": [
                    "A shipping confirmation email will be sent."
                  ]
                }
              ]
            }
          },
          {
            "level_two": {
              "title": "Refunds",
              "content": [
                "All payment transactions are final.",
                "Questions or concerns regarding your refund..."
              ]
            }
          },
          {
            "level_two": {
              "title": "Customer Support",
              "content": [
                "For any questions, please contact our support team..."
              ]
            }
          }
        ]
      }
    },
    {
      "level_one": {
        "title": "Policies",
        "content": [
          {
            "level_two": {
              "title": "Return Policy",
              "content": [
                "This is important." 
              ]
            }
          },
          {
            "level_two": {
              "title": "Privacy Policy",
              "content": [
                "Your privacy is important to us."
              ]
            }
          },
          {
            "level_two": {
              "title": "Terms of Service",
              "content": [
                "Please review our terms of service."
              ]
            }
          }
        ]
      }
    }
  ]
}

been using this:

namespace app\components;

use Yii;

class ContentRenderer
{
    public static function renderContent($content)
    {
        if (is_array($content)) {
            foreach ($content as $item) {
                if (is_array($item)) {
                    // Check if item contains a title and render it
                    if (isset($item['title'])) {
                        echo '<h5>' . Yii::$app->formatter->asText($item['title']) . '</h5>';
                    }
                    // Check if item contains content and call renderContent recursively
                    if (isset($item['content'])) {
                        self::renderContent($item['content']);
                    }
                } elseif (is_string($item)) {
                    // Render strings as paragraphs
                    echo '<p>' . Yii::$app->formatter->asText($item) . '</p>';
                }
            }
        } else {
            // If the content is a string, render it as a paragraph
            echo '<p>' . Yii::$app->formatter->asText($content) . '</p>';
        }
    }
}

with the following for my view file:

<div class="faq-section mt-4">
    <?php if (!empty($data['top_level'])): ?>

    <ul>
        <?php foreach ($data['top_level'] as $section): ?>
            <?php if (isset($section['level_one'])): ?>
                <li>
                    <h4><?= Html::encode($section['level_one']['title']); ?></h4>
                    <?php 
                    // Render content for level_one
                    ContentRenderer::renderContent($section['level_one']['content']); 
                    ?>
                </li>
            <?php endif; ?>
        <?php endforeach; ?>
    </ul>

    <?php else: ?>
    
    <p>No FAQs available.</p>
    
    <?php endif; ?>
</div>