durusmail: qp: Update release 0.1.1 of Evoque Templating
Update release 0.1.1 of Evoque Templating
2008-03-24
2008-03-31
2008-03-31
2008-03-31
Update release 0.1.1 of Evoque Templating
mario ruggier
2008-03-31
On Mar 31, 2008, at 1:55 PM, hollowsun@waitrose.com wrote:
>  Mario,
>
> Thank you for evoque, and integrating it with Gizmo(QP).
>
> On the evoque website would it be possible to show some typical
> example template files? I am keen to see how to put and call multiple
> sub-templates in the same physical file (provided of course they all
> use the same overlay template).

To define multiple sub-templates you just delineate with $begin{name}
and $end{name}. To call them (from anywhere within same file) you do
$evoque{#name}.

There is something that I suspect is not clear. Every file has a
begin{} and end{} implied... (corresponds to beginning and end of the
file). This is for the convenience of being able to $evoque{} any
file/template/content you like, without needing to modifying it. The
difference is how to address it (from another file) -- when no
begin/end you just do $evoque{filename.ext}, but if you explicitly
specify either a begin or an end label (or both), then you must do
$evoque{filename.ext#label}.

However, if you declare that a "file" is an
$overlay{some_other_template}, what you are doing is declaring the
implied top-level template to be an overlay....

Thus, any other sub-templates defined in the file do not inherit the
overlay information in any way, and if you want a sub-template to also
be an overlay then you must explicitly issue an overlay directive
within the sub-template's body. Scan thru the tests for different
scenarios...

> I am trying to aim for one template file per Directory class with each
> Directory component having its own sub-template in a $begin{xyz} ..
> $end{xyz} block. But have been unable to do it so far. As all the
> sub-template blocks use the same master_template (_template.html) I am
> expecting it to be ok to have all the sub-template blocks in one file,
> as there only needs to be one overlay statement?

A limitation on sub-template labels is that each label may be used only
once in the same file, irrespective of the depth level of the
sub-template being defined. You can think of sub-templates as being
defined globally as far as the "top level template" is concerned.

IIUC, you would like to have several sub-templates in the same file
(one per "directory export"), and each of them being an overlay on
_template.html? This would require that each sub-template define a
similarly labeled sub-template in the same file (not allowed -- in
favour of keeping the simple case of a label may be used only once per
file).

While this is possible to achieve (and does not use overlays) to me it
gets to be less clear (and requires the use of the expression form of
the $evoque{} directive i.e. ${evoque(template)} where "template" is a
variable to be interpolated dynamically). I can elaborate on details
for how to achieve that if you like, but my preference is the more
straight forward file-per-export-template.

> I could solve the problem by using one sub-template per file (like the
> examples that ship with Gizmo(QP)) but I kind of like having all the
> sub-template blocks in one html file, as opposed to multiple files or
> using qpy methods to fill in the sub-template specific template
> content. I am sure I am missing something and just need a solid
> example(s).

Yes, an example of doing it this way is at:
http://evoque.gizmojo.org/directives/overlay/positive/

OK, if you really want to see how it can work with all sub-templates
for a directory in one file, let''s say you have a qp/gz Directory A,
and exports X1 and X2... you could do something like this:

---- _template.html
     ... page layout stuff ...
${evoque(export_template)}
     ... page layout stuff ...
----

---- _dirA.html
$begin{X1}
     .... template body for X1 export ...
$end{X1}
$begin{X2}
     .... template body for X2 export ...
$end{X2}
----

Then when you render these, let's say for export X1, you must
dynamically specify the export_template="dirA.html#X1" variable value,
i.e. from python, you would do:


domain.get_template("_template.html").evoque(export_template="dirA.html#
X1")

or, from within another template:

     $evoque{_template.html, export_template="dirA.html#X1"}

and using the gz integration of evoque, the equivalent of the above is:

     page("X1 title", template="_template.html",
export_template="dirA.html#X1")

I hope that clarifies the situation somewhat.

mario

reply