<dtml-in> problem with defined or not defined variable as parameter
Hi, I want to do something like that: <dtml-if id_historie> <dtml-in expr="dbSelect(id_historie=_.str(id_historie))"> <dtml-else> <dtml-in expr="dbSelect(id_historie=_.str(0))"> <dtml-if> [...] </dtml-in> but I get the error " unexpected end tag, for tag </dtml-in>". How can I query my database depending on having id_historie defined or not? Can somebody give me a hint? Thanks, Patrick
Patrick Ulmer wrote:
Hi,
I want to do something like that:
<dtml-if id_historie> <dtml-in expr="dbSelect(id_historie=_.str(id_historie))"> <dtml-else> <dtml-in expr="dbSelect(id_historie=_.str(0))"> <dtml-if>
[...]
</dtml-in>
but I get the error " unexpected end tag, for tag </dtml-in>". How can I query my database depending on having id_historie defined or not? Can somebody give me a hint?
You can't put <dtml-in> in a dtml-if. You must include the </dtml-in>. This is because <dtml-in> and <dtml-if>, and all other dtml-tag that comes in pairs, defines a DTML block in between them and you can't have overlaping blaocks. When the DTML "page" is rendered the DTML blocks are executed as a whole with it's local context. In the exaple above I would set id_historie in a <dtml-let> tag: <dtml-let id_historie="id_historie or 0"> <dtml-in expr="dbSelect(id_historie=_.str(id_historie))"> ... </dtml-in> </dtml-let> Best Regards, Johan Carlsson -- Johan Carlsson Tel: + 46 8 31 24 94 Colliberty Mob: + 46 70 558 25 24 Torsgatan 72 Email: johanc@easypublisher.com SE-113 37 STOCKHOLM
Hi,
I want to do something like that:
<dtml-if id_historie> <dtml-in expr="dbSelect(id_historie=_.str(id_historie))"> <dtml-else> <dtml-in expr="dbSelect(id_historie=_.str(0))"> <dtml-if>
[...]
</dtml-in>
but I get the error " unexpected end tag, for tag </dtml-in>". How can I query my database depending on having id_historie defined or not? Can somebody give me a hint?
In the exaple above I would set id_historie in a <dtml-let> tag:
<dtml-let id_historie="id_historie or 0"> <dtml-in expr="dbSelect(id_historie=_.str(id_historie))"> ... </dtml-in> </dtml-let>
Sorry, but now I got the error "global name 'id_historie' is not defined" in line <dtml-let....>. Best Regards, Patrick Ulmer
Patrick Ulmer wrote:
Hi,
I want to do something like that:
<dtml-if id_historie> <dtml-in expr="dbSelect(id_historie=_.str(id_historie))"> <dtml-else> <dtml-in expr="dbSelect(id_historie=_.str(0))"> <dtml-if>
[...]
</dtml-in>
but I get the error " unexpected end tag, for tag </dtml-in>". How can I query my database depending on having id_historie defined or not? Can somebody give me a hint?
In the exaple above I would set id_historie in a <dtml-let> tag:
<dtml-let id_historie="id_historie or 0"> <dtml-in expr="dbSelect(id_historie=_.str(id_historie))"> ... </dtml-in> </dtml-let>
Sorry, but now I got the error "global name 'id_historie' is not defined" in line <dtml-let....>.
<dtml-let id_historie="_.getattr(_, 'id_historie', 0)"> or <dtml-let id_historie="_.has_key('id_historie') and id_historie or 0)"> -- Johan Carlsson Tel: + 46 8 31 24 94 Colliberty Mob: + 46 70 558 25 24 Torsgatan 72 Email: johanc@easypublisher.com SE-113 37 STOCKHOLM
Patrick Ulmer wrote:
Hi,
I want to do something like that:
<dtml-if id_historie> <dtml-in expr="dbSelect(id_historie=_.str(id_historie))"> <dtml-else> <dtml-in expr="dbSelect(id_historie=_.str(0))"> <dtml-if>
[...]
</dtml-in>
but I get the error " unexpected end tag, for tag </dtml-in>". How can I query my database depending on having id_historie defined or not? Can somebody give me a hint?
I've seen the other replies, but I think your original example should work too (I haven't used dtml in a long time, so I'm not sure). The problem here is that each "<dtml-in>" has to have an own closing tag: <dtml-if id_historie> <dtml-in expr="dbSelect(id_historie=_.str(id_historie))"> Do something </dtml-in> <dtml-else> <dtml-in expr="dbSelect(id_historie=_.str(0))"> Do another thing </dtml-in> <dtml-if>
I've seen the other replies, but I think your original example should work too (I haven't used dtml in a long time, so I'm not sure). The problem here is that each "<dtml-in>" has to have an own closing tag:
<dtml-if id_historie> <dtml-in expr="dbSelect(id_historie=_.str(id_historie))"> Do something </dtml-in> <dtml-else> <dtml-in expr="dbSelect(id_historie=_.str(0))"> Do another thing </dtml-in> <dtml-if> Ops, I realized that this peace of code is ineficient and the <dtml-let> suggestion is better. Anyway, keep on mind that for each <dtml-in> you have to have a </dtml-in>
participants (3)
-
Johan Carlsson -
Josef Meile -
Patrick Ulmer