[Bese-devel] TAL und yaclml

Marco Baringer mb at bese.it
Mon Jul 25 10:10:19 UTC 2005


Friedrich Dominicus <frido at q-software-solutions.de> writes:

> Well you have explained how things work but I'm missing one thing. 
> How to call a tal file from within a defaction.
>
> at the moment the code is
> defaction
> ...
>                                (make-instance 'trans-product
>                                               :product-id (id (product item))
>                                               :tag (tag (product item))
>                                               :num-copies copies
>                                               :distribution ""
>                                               :usage ""
>                                               :price price))))
>                   ;; (inspect obj)
>                 (push obj prod-list)))))
>
>     (call 'trans-info
>           :products-in-basket (nreverse prod-list))))
>
>
> Now if I cal 'trans-info then in the end I call the render-on
> method. But what do I have to do "call" a tal template file?

i've been thinking about a 'show' macro (and accompanying component)
for quite a while. this is as good as a time as any to write one
(untested but conceptually correct):

(defcomponent show-template-component (template-component)
  ((env :accessor env :initarg :env)))

(defmethod template-component-environment nconc
    ((component show-template-component))
  (env component))

(defmacro show (page-name &rest env)
  `(call 'show-template-component :template-tame ,page-name
                                  :env (tal-env , at env)))

you'd then use this in an action like this:

(defaction 
  ...
  (show "whatever.tal"
        :products-in-basket (mapcar (lambda (product)
                                      (tal-env 'item product))
                                    prod-list)))

and then you'd access the prod-list with something like:

<ul>
  <li tal:dolist="$:products-in-basket">
    <b tal:content="$item">ITEM GOES HERE</b>
  </li>
</ul>

avoiding the ugly $:products-in-basket is fairly easy, just pass
'products-in-basket ta show instead of :products-in-basket and make
sure you add a tal:in-package attribute somewhere in the tal file.

since this is a component the show macro won't return until your
template calls answer, this can be done easily by adding a like whcih
calls the OK action (all components can do this and it very simply
calls answer):

<ucw:a action="(ok $component)">Done.</a>

(the $component tal environment variable is setup by the
template-component class and, the symbol itself, is exported from the
ucw package).

hth.

-- 
-Marco
Ring the bells that still can ring.
Forget the perfect offering.
There is a crack in everything.
That's how the light gets in.
	-Leonard Cohen



More information about the bese-devel mailing list