Dynamic and custom sections

On my website I have two pages where the sections are very different in structure, so atm I made 4 snippets and placed the snippets on these two pages like this.

site/templates/page_1

On page_1

<?php snippet('header') ?>
<?php snippet('snippet_section_1') ?>
<?php snippet('snippet_section_2') ?>
<?php snippet('snippet_section_3') ?>
<?php snippet('snippet_section_4') ?>
<?php snippet('footer') ?>

Can I write this different so that there are more possibility’s to rearrange the sections in the cms?

And also that I can add a custom section here.

Thanks

What are these sections made from?

Just html and the content that is coming from the content folder

But that’s exactly what I wanted to know in more detail. Subpages? Structure field items?

Instead of actually adding each snippet name separately, you can loop through the pages/items and call snippets by intended template name, for example. Users can reorder pages/items to change the order in which sections appear on the site.

Or are the sections defined from different parts of the site?

Have a look at the one-pager sample in the docs. I think this is what you need.

1 Like

The page has a subpage for each snippet with a .txt file from which fields are read and occasionally also a subpage containing a subelement that is used a number of times (like team members which loads in different members a few times in this subpage.)

So for example

`content/my_page/subpage_1/.txt_file`

`content/my_page/subpage_2/member_1/txt_file`
`content/my_page/subpage_2/member_2/txt_file`
`content/my_page/subpage_2/member_3/txt_file`

`content/my_page/subpage_3/txt_file`

And so I would like to render all the subpages more dynamically and not like this:

<?php snippet('header') ?>
<?php snippet('snippet_section_1') ?>
<?php snippet('snippet_section_2') ?>
<?php snippet('snippet_section_3') ?>
<?php snippet('snippet_section_4') ?>
<?php snippet('footer') ?>
foreach ($page->children()->listed() as $child) {
  snippet($child->intendedTemplate());
}

Name the snippets according to the text files.

1 Like