Templating » History » Revision 11
« Previous |
Revision 11/32
(diff)
| Next »
Stefan Sprenger, 2012-01-10 17:32
Templating¶
EXT:solr uses an advanced version of the marker templating system. The reason for this is a pure historical one. When we started working on the extension in early 2009 TYPO3 4.2 still was the current version and TYPO3 4.3 was still in development, and extbase, fluid were not stable enough yet. We also did not have to completely invent the template engine as it was taken from the code base of EXT:community.
The template engine offers features and a syntax similar like known from fluid. This includes if conditions, loops, and view helpers. It uses the known triple hash, i.e., ### markers though.
In the following sections we explain the several features of the templating system.
Subparts¶
Subparts of a template have a name and are limited by a beginning and an end. E.g. the subpart SOLR_SEARCH_FORM is defined as following:
<!-- ###SOLR_SEARCH_FORM### begin --> /* Some HTML markup */ <!-- ###SOLR_SEARCH_FORM### end -->
Conditions¶
EXT:solr provides the classic if conditions that you are used to in PHP. They consist of two comparands, an operator and a subpart that gets
rendered if the condition is fulfilled.
The following operators are supported:
- ==
- !=
- <
- <=
- >
- >=
- %
E.g. if you want to render a given HTML markup only if the result document's type equals "pages" you can use the == operator:
<!-- ###IF:###RESULT_DOCUMENT.TYPE###|==|pages### begin --> <strong>It's a page!</strong> <!-- ###IF:###RESULT_DOCUMENT.TYPE###|==|pages### end -->
At the moment, we are not supporting "else".
Loops¶
View helpers¶
We provide several view helpers that keep your templates clean. View helpers are basically functions that can get called in templates and return some
kind of HTML markup.
They can have strings, numbers or subparts as arguments.
By default EXT:solr provides the following view helpers that are located and documented inside the folder classes/viewhelper of the project:
- CROP
- CURRENT_RESULT_NUMBER
- DATE
- FACET
- LINK
- LLL
- ODD_EVEN
- RELEVANCE
- RELEVANCE_BAR
- SOLR_LINK
- SORT_INDICATOR
- SORT_URL
- TS
E.g. if you want to render the localization of the label welcome_message you can use the LLL view helper:
###LLL:welcome_message###
Arguments are introduced by a colon (:) and divided by a pipe (|).
Let's have a look at a view helper with multiple arguments. The CROP view helper can be used to render a part of a string.
E.g. if you want to render the first 5 characters of the string "Apache Solr" you can use CROP as following:
###CROP:Apache Solr|5###
The length of the cropped string is provided as the second argument.
Write a custom view helper¶
Updated by Stefan Sprenger about 9 years ago · 11 revisions