Create a container for each page field?

In the same page, i want to display content in separated containers (boxes).

Let`s say for example that i have the following inside /1-About/about.txt

Title: About
# This info in a container
(image: container1.img)
# This info in another container
(image: container2.img)

I want to make it so the content inside each container field is displayed in separated div , just as we have using a foreach($page->children()->visible() in a blog or a gallery, but in my case i do not want subpages, just segmented info inside the page’s .txt

I was able to do that inserting HTML markup inside the .txt file, but i want to do this dynamically with PHP, for the number of n containers.

Well, I’d use a structure field for that, but I suppose you could somehow use the content object as a starting point and then filter out the fields that start with container. You can use this piece of code as a starting point which I once collected from the old forum:

$content = $page->content();
foreach ($content as $key => $value) {
  if ($key == "fields") {
    foreach ($value as $field) {
      echo  $page->$field() ;
1 Like