User Guides

Sections

Sections are one off entities used to hold a group of content fields, these are usually used for individual sections of a website. For example a basic website may only have three or four sections defined for things such as a homepage, about page, contact page and possibly some sort of services/portfolio page.

Sections defined in the content.yaml config file are automatically displayed in the admin panel.


Example Section Definition

The rest of this page assumes that you have the below section defined. The examples beyond this point also assume that you are interacting with LexasCMS from within a template.

sections:
  Services:
    fields:
      - { name: "heading", type: "text", title: "Page Heading" }
      - { name: "banner", type: "image", widths: [1140], title: "Page Banner" }
      - { name: "copy", type: "html", title: "Page Copy" }

Retrieving a Section

Before you can retrieve content from a section, you need to retrieve the section itself. The below example displays how you can retrieve the 'Services' section defined above.

{{ cms.content.section("Services") }}

Retrieving a Content Field

Once you have access to the section itself, you can then retrieve content fields from it. The following example shows how you could retrieve and display the heading content type in a template

{{ cms.content.section("Services").heading.html() }}

For more information about working with content fields, see the Content Fields section.


Further Reading

For more information about sections in LexasCMS, we recommend that you take a look at the API reference.