The Section
command allows a template section, containing data and/or PTPScript code, to be defined. In this context, a section is essentially a sub-template, just like an included template file, except that it is not in a separate file. It has its own Variable "scope", which is set when the section is included using the Include
command.
When a Section
command is first encountered, the section data is not displayed, but is instead stored for later use. When required, the macro can be displayed using the Include
command.
There are two commands in the Section
family - Section
and EndSection
. Each Section
command has to have a corresponding EndSection
command.
The Section
command consists of the command, followed by the section name. The EndSection
command does not use an expression, and so will ignore any expression given.
For example:
{ section Greeting }… Hi there! { endsection }… { include section Greeting }
Hi there!
Section
names are case-insensitive, just like Macros and Functions.
Section
definitions and calls can be nested indefinitely within other Section
definitions, and within other command structures. All Section
definitions are global in scope - that is, they can be called from anywhere, no matter where they were defined. However, if defined within a section, the containing section has to be called before the definition will be processed.
Sections can be re-declared without error. The latest definition will apply for all code following it.
Sometimes it may be necessary to check for a section, and in such a situation, type checking should be used to determine whether the section has been defined.
For example:
{ if "Greeting" is a section }… { include section Greeting } { endif }