craft.sections
This document is for a version of Craft CMS that is no longer supported. Please refer to the latest version →
You can get info about your site’s sections using craft.sections
.
#Methods
The following methods are available:
#getAllSections()
Returns an array of SectionModel objects representing each of your site’s sections.
{% set sections = craft.sections.getAllSections() %}
#getEditableSections()
Returns an array of SectionModel objects representing each of your site’s sections, which the current user has permission to edit entries in.
{% set sections = craft.sections.getEditableSections() %}
#getTotalSections()
Returns the total number of sections your site has.
{% set total = craft.sections.getTotalSections() %}
#getTotalEditableSections()
Returns the total number of sections your site has, which the current user has permission to edit entries in.
{% set total = craft.sections.getTotalEditableSections() %}
#getSectionById( sectionId )
Returns a SectionModel object representing a section in your site, by its ID.
{% set sectionId = craft.request.getSegment(3) %}
{% set section = craft.sections.getSectionById(sectionId) %}
#getSectionByHandle( handle )
Returns a SectionModel object representing a section in your site, by its handle.
{% set handle = craft.request.getSegment(3) %}
{% set section = craft.sections.getSectionByHandle(handle) %}