Sections and data formats in OPT
This tutorial shows, how to use sections and data formats in Open Power Template, two unique and powerful features that make writing templates much simpler and faster.
Table of Contents
One of the most useful features in template engine Open Power Templare are sections. They are used to display lists, but contrary to ordinary loops known from other template engines and programming languages, it provides lots of unique options that make your life simpler. In this article we are going to show, how to use sections in your projects and what are data formats, another powerful feature which however may cause some problems at the beginning.
Add new comment
Comments
#1 Peter Wilson over 2 years ago Reply to this comment
Good article
nice tutorial. this is something i needed and it would be nice to see more texts like this. i have one question: is it possible to read the section data from the variable, but different than the section name with array format?
#1.1 Zyx about 17 hours later
Re: #1
Yes, it's possible. Use the `datasource` section attribute:
~~~~
<opt:section name="foo" datasource="$bar">
</opt:section>
~~~~
Just remember that OPT ignores the "parent" attribute then and does not link it with the parent section, if your section is nested.