Sections is another concept you have to understand. Essentially all they do is contain your created fields. Simply drag and drop the fields you require into your section and make them required if necessary.
Sections have three main types, singles, which are individual pages, multiples which can be like posts or products and globals - as the name suggests these can be accessed on any page in your templates and are useful for setting your site's main look and feel.
Singles are used for one-off pages that have unique content requirements, such as:
- the homepage
- an About Us page
- a Contact Us page
Unlike the other section types, Singles only have one entry associated with them.
Multiples are used for streams of similar content, such as:
- a Blog
- a News section
The main difference between a single and a multiple section type is that a multiple section type must have a folder with the section name and MUST contain a php file called _entry.php and index.php.
index.php is where you list all the multiples, _entry.php is the actual detail for that type
-- blog(Folder) ---- _entry.php(File) ---- index.php(File)
If you are unsure of the folder and file layout of a multiple, simply click the boiler plate template generator and it will generate the folder structure and files in your view file. Then you can simply inspect them with your favourite text editor (we recommend VS Code) and edit these files.
When you create a new 'Multiple' section you can loop through all the entries in the index.php file by using the following syntax.
<?php foreach ($multiples['blog'] as $key) : ?> <?= $key['title'] ?> <?php endforeach; ?>
Globals are very similar to singles, in that you create the fields and section as you would normally, the only difference is you store the content by clicking on the global (world) icon in your dashboard.
Accessing global content in your template files is slightly different. Instead of doing :
<?= $fieldHandle ?>
You would do:
<?= $globalName['fieldHandle'] ?>
The beauty about globals is that they can be accessed on ANY page in your template.
Sections can either be singles, for a single page, multiples for like a blog, or globals where they can be accessed anywhere