theaterelch

Christian Probst

Bern, Schweiz
Kontakt: info@theaterelch.ch
Tojo - Reitschule Bern · Berner Münster · Schlachthaus · Anatomisches Institut - Universität Bern · Kuppelsaal - Universität Bern · Der Berner Bremgartenfriedhof · Metallgarten Worb · Nydeggbrücke · Friedhof Enzenbühl - Zürich · Friedhof am Hörnli - Basel · Klassenzimmer · Hof Wyssloch

spacer

Hilfe: SQLEdit, Template usage

Starting from version 06.00.09, SQLEdit template engine becomes most powerful. In the previous versions, the fields was constructed through TMPL_LOOP tag. The HTML code contained in this section has been used, therefore, in order to construct, for every column of the database, the corresponding HTML code.

If, as an example, the TMPL_LOOP section of the "example1" template was

<table>

 <TMPL_LOOP name="fields_loop">

     <tr>

         <td><TMPL_VAR NAME="field.label">: </td>

         <td><TMPL_VAR NAME="field.form"></td>

     </tr>

 </TMPL_LOOP>

</table>

 

the fields of the database had been formatted on lines of a table where in the first column appeared, aligned to right, the name of the field of the database whereas in a second column, the element of form the correspondent for the editing appeared.

Taking, as an example, four columns of type text, "a", "b", "c", "d", the SQLEdit module that is generated with "example1" template, appears like

<table>
    <tr>
        <td>a</td>
        <td><INPUT TYPE="text" NAME="a" VALUE="...."></TD>
    <tr>
    <tr>
        <td>b</td>
        <td><INPUT TYPE="text" NAME="b" VALUE="...."></TD>
    <tr>
    <tr>
        <td>c</td>
        <td><INPUT TYPE="text" NAME="c" VALUE="...."></TD>
    <tr>
    <tr>
        <td>d</td>
        <td><INPUT TYPE="text" NAME="d" VALUE="...."></TD>
    <tr>
</table>

 

Even though this method was already sufficiently personalizzabile because was possible to format, with any graphical layout, elements of the form, it was not, as an example, possible to configure different fields with different formats, or to put more fields on the same line.

In version 06.00.09 this templating model remains the same, for compatibility, but it becomes deprecated in favor of the new model in which, beyond to the global template of the SQLEdit element, it has been added a templating model for the single fields.

As an example, we consider the example above and see how to duplicate it in the new templating model. The template to use will be something type

<table>

    <TMPL_VAR name="form.fields.template">

</table>

 

that, you can see, it has not more an element TMPL_LOOP but, to its place, is a variable TMPL_VAR. This variable will be replaced with the concatenation of the single template of the single fields.

Where are fields template defined? In the same tab, there is, starting from version 06.00.09, a new element called "Default field template". This element defines the default field template to use, unless otherwise specified.¶ Starting from now, we will define:

  • global template : template of the SQLEdit module, that is the field "Template" of tab "Layout" in the global configuration of the SQLEdit element

  • default field template: the new element "Default field template" as soon as seen, that is the field "Default field template" of tab "Layout" in the global configuration of the SQLEdit element

  • field template : the template that, as we will see, it is definable in every single field.

  • template for fields: whichever template present in the list that appears in the default field template or in the field template ones (namespace: SQLEdit_field)

We go now to define new template for fields, with this code

<tr>
    <td><TMPL_VAR NAME="field.label">: </td>
    <td><TMPL_VAR NAME="field.form"></td>
</tr>

 

that, you see, it is equal to HTML code inside TMPL_LOOP in template "example1". Using these configuration the result will coincide exactly with what we obtained with the template "example1".

The use of the old or new model of templating is automatic. If you use, in the global template, the TMPL_LOOP, automatically the configuration of the fields template will be ignored, if the <TMPL_VAR name="form.fields.template TMPL_VAR> is used, it will be used this new formulation.

Up to now what we have create corresponds already to how much could be made with the old model of templating. What then differentiates the new one from the old one? The difference is in the fact that now exists, in every field, a property that defines the field template to use. It is set up, by default, to the value "inherited " that is to use the default field template in the tab "Layout" of the global configuration of the SQLEdit element.

But modifying such configuration it is possible to alter the layout of single elements.¶ We see, as an example how it is possible to put two fields on one same line.

Defining a template for the fields named "two_columns" in this way (in order to set up these template on single elements, we will have also need of the admin buttons:

<tr>
    <td><TMPL_VAR name="field.adminTools"> <TMPL_VAR NAME="field.label"></td>
    <td colspan="3"><TMPL_VAR NAME="field.form"></td>
</tr>

 

and using it, as default field template, the layout of the form do not change. Now we go to define two more templates for the fields, "two_columns_1" as:

<tr>
    <td><TMPL_VAR name="field.adminTools"> <TMPL_VAR NAME="field.label"></td>
    <td><TMPL_VAR NAME="field.form"></td>

 

ad "two_columns_2" as:

    <td><TMPL_VAR name="field.adminTools"> <TMPL_VAR NAME="field.label"></td>
    <td><TMPL_VAR NAME="field.form"></td>
</tr>

 

We go now in the configuration of the field "a" and change the field template from "inherance" to "two_columns_1". We go therefore in the configuration of the field "b" and change the field template from "inherance" to "two_columns_2".

Saving the result, it will see that fields "a" and "b" lie now on the same line whereas fields "c" and "d" continue to be disposed on two lines.

Corresponding HTML code will be therefore:

<!-- Template globale -->
<table>
<!-- il <TMPL_VAR name="form.fields.template"> viene sostituito con -->
<!-- Template "two_column_1" -->
    <tr>
        <td>a</td>
        <td><INPUT TYPE="text" NAME="a" VALUE="...."></td>
<!-- Template "two_column_2" -->
        <td>b</td>
        <td><INPUT TYPE="text" NAME="b" VALUE="...."></td>

    </tr>
<!-- Template di default "two_column" -->
    <tr>
        <td>c</td>
        <td colspan="3"><INPUT TYPE="text" NAME="c" VALUE="...."></td>
    </tr>
<!-- Template di default "two_column" -->
    <tr>
        <td>d</td>
        <td colspan="3"><INPUT TYPE="text" NAME="d" VALUE="...."></td>
    </tr>
</table>

 

that it corresponds to what was supposed

As an ulterior example, we suppose to wish to insert a horizontal line of separation between the first line, the one with fields "to" and "b" from the second, the one with field "c". We create, for this purpose, an ulterior template for the fields as it follows:

<tr>

    <td colspan="4"><hr></td>

</tr>

<tr>
    <td><TMPL_VAR name="field.adminTools"> <TMPL_VAR NAME="field.label"></td>
    <td colspan="3"><TMPL_VAR NAME="field.form"></td>
</tr>

 

and named "two_columns_hr" and apply this template to single field "c", the intentional result will be obtained.

Siehe auch:

Mein Benutzerkonto