The XML-dtml notation "&dtml-variable;"
Hi, I just learned about the XML-dtml notation for inserting values inside XML-strings. I find this useful, and use it both in HTML and XML. But, isn't there a way to supply a default value (if the variable lookup fails)? Something like &dtml-variable default-value; Thanks in advance, //johan
Johan Carlsson wrote:
Hi, I just learned about the XML-dtml notation for inserting values inside XML-strings.
I find this useful, and use it both in HTML and XML.
But, isn't there a way to supply a default value (if the variable lookup fails)?
Something like &dtml-variable default-value;
I think that would be stretching the semantics of <dtml-var> a bit beyond where they should go. Just wrap the entity in a <dtml-if> and test for the variable existence beforehand. Longer, but much more clear. -Michel
On 11/4/99 11:31 AM, Michel Pelletier at michel@digicool.com wrote:
Johan Carlsson wrote:
Hi, I just learned about the XML-dtml notation for inserting values inside XML-strings.
I find this useful, and use it both in HTML and XML.
But, isn't there a way to supply a default value (if the variable lookup fails)?
Something like &dtml-variable default-value;
I think that would be stretching the semantics of <dtml-var> a bit beyond where they should go. Just wrap the entity in a <dtml-if> and test for the variable existence beforehand. Longer, but much more clear.
Would something like this be more palatable? <dtml-var foo default="Empty"> Chris -- | Christopher Petrilli Python Powered Digital Creations, Inc. | petrilli@digicool.com http://www.digicool.com
At 10:33 am -0500 4/11/99, Christopher Petrilli wrote:
Would something like this be more palatable?
<dtml-var foo default="Empty">
Definitely. I think it would certainly help newbies to get up to speed if something like this were available (memories of that first traceback error!). Certainly a lot of my errors have been due to variables that weren't available when I used them. Tone ------ Dr Tony McDonald, FMCC, Networked Learning Environments Project http://nle.ncl.ac.uk/ The Medical School, Newcastle University Tel: +44 191 222 5888 Fingerprint: 3450 876D FA41 B926 D3DD F8C3 F2D0 C3B9 8B38 18A2
Would something like this be more palatable?
<dtml-var foo default="Empty">
It would definitely be a start. This is the scenario I been working with today that got me thinking: (thinking because it's allot of work for do simple stuff, and I'm lacy ;) I prefer the &dtml-Var; tag for the XML validity. Isn't the &dtml-Var; is equal to the <dtml-var Var> by the way? (I have just glanced trough the source) I am working on a mail form where I what to use the same template as the initial mail-form and as the "you need to fill out these fields correctly"-error mail-form. It looks like this: <form ...> ... <input ... name="email" value="&dtml-email;"> ... </form> Not this breaks when used as the initial mail-form. Now I considering the solutions: 1. Using try to ignore exceptions: <dtml-try> ... <input ... name="email" value="&dtml-email;"> ... <input ... name="name" value="&dtml-name;"> ... <input ... name="adress" value="&dtml-adress;"> <dtml-except NameError, Key not found(or what ever exception)> <dtml-do-next > # And this returns to execute the next dtml-statement after the exception </dtml-try> 2. The default value version (described in earlier mail): (a) <dtml-with "dtml-var-default='empty string'"> ... <input ... name="email" value="&dtml-email default='';"> ... </dtml-with> (b) ... <input ... name="email" value="&dtml-email default='';"> ... # (is this valid XML by the way, with a space in the "&...;"? # not considering the lack of "</input>") Are you reading what I'm getting at? DTML has allot of akwardties that really scares away people, specially newbees and people with less talent in advanced programming (e.g.. ASP programmer's and HTML/JavaScript coders ;-) //johan
On 11/4/99 2:39 PM, Johan Carlsson at johanc@torped.se wrote:
Would something like this be more palatable?
<dtml-var foo default="Empty">
It would definitely be a start.
I just checked in a change to the <dtml-var> tag that allows the following: <dtml-var foo missing> renders to: '' when foo is missing <dtml-var foo missing="x"> renders to "x" when foo is missing. And allows teh entity reference syntax to work: &dtml.missing-foo; renders to '' when missing. This should fix most of what we've been seeing and people have been complaining about :-) Chris -- | Christopher Petrilli Python Powered Digital Creations, Inc. | petrilli@digicool.com http://www.digicool.com
Christopher Petrilli wrote:
&dtml.missing-foo;
renders to '' when missing.
Great stuff! Would it make sense to other folks (it does to me) to make dtml-entities default to missing as well as html_quote? I can't recall a situation yet where I really wanted my page to choke because a variable was missing <wink>. Now that I think about it, perhaps there ought to be a (global? per-request?) way of choosing a set of default formats for dtml-entities. Maybe check for a tokens-type property (or list-of-strings request variable) DTML_ENTITY_FORMATS? Cheers, Evan @ 4-am
participants (5)
-
Christopher Petrilli -
Evan Simpson -
Johan Carlsson -
Michel Pelletier -
Tony McDonald