Skip to content
Snippets Groups Projects

Twig new

Merged Nicola Chiapolini requested to merge twig_new into master
@@ -729,6 +729,8 @@ Insert one or more QFQ content elements on a Typo3 page. Specify column and lang
The title of the QFQ content element will not be rendered on the frontend. It's only visible to the webmaster in the
backend for orientation.
.. _qfq_keywords:
QFQ Keywords (Bodytext)
^^^^^^^^^^^^^^^^^^^^^^^
@@ -5151,33 +5153,60 @@ The HTML output, displayed on the page, resulting from only this definition, cou
I.e., QFQ will simply output the content of the SQL result row after row for each single level.
However, we can pass the result of the query to the `Twig template engine <https://twig.symphony.com/>`_
in order to fill a template with the data.::
Format output: mix style and content
""""""""""""""""""""""""""""""""""""
Variant 1: pure SQL
;;;;;;;;;;;;;;;;;;;
To format the upper example, just create additional columns::
10.sql = SELECT firstName, ", ", lastName, "<br>" FROM person
HTML output::
Doe, John<br>
Miller, Jane<br>
Star, Frank<br>
Variant 2: SQL plus QFQ helper
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
QFQ provides several helper functions to wrap rows and columns, or to separate them. In this example 'fsep'='field
separate and 'rend' = row end:
10.sql = SELECT firstName, lastName FROM person
10.twig = {% for row in result %}
{{ row.lastName }}, {{ row.firstName }<br />
{% endfor %}
10.fsep = ', '
10.rend = <br>
HTML output::
Doe, John<br />
Miller, Jane<br />
Star, Frank<br />
Doe, John<br>
Miller, Jane<br>
Star, Frank<br>
Check out all QFQ helpers under qfq_keywords_.
In addition, QFQ provides option to modify (wrap) the output by setting the values of various keys
for each level: 10.rsep=<br/> for example tells QFQ to separate the rows of the result by a HTML-line break.
The final result in this case is::
Due to mixing style and content, this becomes harder to maintain with more complex layout.
10.sql = SELECT CONCAT(lastName, ", ", lastName, " ") AS name FROM person
10.rsep = <br />
Format output: separate style and content
"""""""""""""""""""""""""""""""""""""""""
The result of the query can be passed to the `Twig template engine <https://twig.symphony.com/>`_
in order to fill a template with the data.::
10.sql = SELECT firstName, lastName FROM person
10.twig = {% for row in result %}
{{ row.lastName }}, {{ row.firstName }<br />
{% endfor %}
HTML output::
Doe, John<br />Miller, Jane<br />Star, Frank
Doe, John<br>
Miller, Jane<br>
Star, Frank<br>
This approach might be easier for very simple reports, but will quickly create an unmaintainable mess for more complex needs.
It is therefore strongly advised to use the Twig instead.
Check out using-twig_.
.. _`syntax-of-report`:
@@ -5247,13 +5276,11 @@ There are extensive ways to wrap columns and rows. See :ref:`wrapping-rows-and-c
Using Twig
----------
How to wirte Twig templates is documented by the `Twig Project <https://twig.symphony.com/>`_
and not covered here.
How to write Twig templates is documented by the `Twig Project <https://twig.symphony.com/>`_.
QFQ passes the result of a given query to the corresponding Twig template using the variable
QFQ passes the result of a given query to the corresponding Twig template using the Twig variable
`result`. So templates need to use this variable to access the result of a query.
Specifying a Template
^^^^^^^^^^^^^^^^^^^^^
By default the string passed to the **twig**-key is used as template directly,
@@ -5268,15 +5295,15 @@ file specified.::
10.twig = file:table_sortable.html.twig
Pathes relative to *<site path>* and if the file is not found there relative to
The file is searched relative to *<site path>* and if the file is not found there, it's searched relative to
QFQ's *twig_template* folder where the included base templates are stored.
The following templates are availabel:
The following templates are available:
``tables/default.html.twig``
A basic table with column headers, sorting and column filters using bootstrap.
A basic table with column headers, sorting and column filters using tablesorter and bootstrap.
``tables/default.html.twig``
``tables/single_vertical.html.twig``
A template to display the values of a single record in a vertical table.
Links
@@ -5288,7 +5315,7 @@ using the `qfqlink` filter::
will render a link to *http://www.example.com*.
Availabel Store Variables
Available Store Variables
^^^^^^^^^^^^^^^^^^^^^^^^^
QFQ also provides access to the following stores via the template context.
@@ -5299,7 +5326,7 @@ QFQ also provides access to the following stores via the template context.
* User
All four stores are accessed using their lower case name as attribute of the
context variable `store`. The active Typo3 front-end user is therefor availabel as::
context variable `store`. The active Typo3 front-end user is therefor available as::
{{ store.typo3.feUser }}
@@ -5339,6 +5366,7 @@ and then displays the files in a nice table with links to the files.
Debug the bodytext
------------------
The parsed bodytext could be displayed by activating 'showDebugInfo' (:ref:`debug`) and specifying
::
@@ -5627,8 +5655,8 @@ Special column names
.. note::
Special column names are a legacy feature and should be avoided. Rendering of output should be done
using Twig when ever possible.
Twig: respect that the 'special column name'-columns are rendered before Twig becomes active. The recommended
way by using Twig is *not to use* special column names at all. Use the Twig version *qfqLink*.
* Special column names always start with '_'.
* Column names, which start with a '_' and which are not reserved (=special column name), will not be printed. Nevertheless,
Loading