non static size parameter in dtml-var
I have a dtml-var tag that is being repeated over and over inside of a dtml-in tag. I would like the client to be able to custimize the maximum amount of text output they see, so i did something like the following: <dtml-var "item['title']" size="getTitleLen()"> Where getTitleLen is a method which returns an integer of how many characters max the title is to be. However, when i have this dtml method rendered, i get the following error: a size attribute was used in a var tag with a non-integer value. Is there a do what i am trying to do? If so, how could i do it? If not, why isn't this possible? thanks sRp -- Scott Parish http://srparish.net
Scott Parish wrote:
I have a dtml-var tag that is being repeated over and over inside of a dtml-in tag. I would like the client to be able to custimize the maximum amount of text output they see, so i did something like the following:
<dtml-var "item['title']" size="getTitleLen()">
Where getTitleLen is a method which returns an integer of how many characters max the title is to be. However, when i have this dtml method rendered, i get the following error:
a size attribute was used in a var tag with a non-integer value.
Looks like you'll need to patch lib/python/DocumentTemplate/DT_Var.py to get this working. 326,328c326,331 < except: raise 'Document Error',( < '''a <code>size</code> attribute was used in a <code>var</code> < tag with a non-integer value.''') ---
except: try: size=atoi(str(md[size])) except: raise 'Document Error',( '''a <code>size</code> attribute was used in a <code>var</code> tag with a non-integer value.''')
After this patch, you can use normal numeric literals, or you can use values from the namespace. Here's an example: index_html dtml-method: ---- <dtml-var standard_html_header> <h2><dtml-var title_or_id></h2> <p> This is the <dtml-var id> Document. </p> <dtml-var "'Hello world'" size="getLen"> <dtml-var standard_html_footer> ---- getLen dtml-method: ---- <dtml-return "5"> ---- -- Steve Alexander Software Engineer Cat-Box limited
Steve Alexander wrote:
Scott Parish wrote:
I have a dtml-var tag that is being repeated over and over inside of a dtml-in tag. I would like the client to be able to custimize the maximum amount of text output they see, so i did something like the following:
<dtml-var "item['title']" size="getTitleLen()">
Where getTitleLen is a method which returns an integer of how many characters max the title is to be. However, when i have this dtml method rendered, i get the following error:
a size attribute was used in a var tag with a non-integer value.
Looks like you'll need to patch lib/python/DocumentTemplate/DT_Var.py to get this working.
326,328c326,331 < except: raise 'Document Error',( < '''a <code>size</code> attribute was used in a <code>var</code> < tag with a non-integer value.''') ---
except: try: size=atoi(str(md[size])) except: raise 'Document Error',( '''a <code>size</code> attribute was used in a <code>var</code> tag with a non-integer value.''')
After this patch, you can use normal numeric literals, or you can use values from the namespace.
Except that the indentation of the patch hasn't come out right :-( The final code should look like this: if have_arg('size'): size=args['size'] try: size=atoi(size) except: try: size=atoi(str(md[size])) except: raise 'Document Error',( '''a <code>size</code> attribute was used in a <code>var</code> tag with a non-integer value.''') Narrative: If the literal value of the attribute "size" doesn't easily parse into an integer, try looking up the value of the attribute "size" in the namespace, and see if that wants to be a number. If all that fails, give normal error message. -- Steve Alexander Software Engineer Cat-Box limited
Thus spake Steve Alexander (steve@cat-box.net):
Steve Alexander wrote:
Scott Parish wrote:
I have a dtml-var tag that is being repeated over and over inside of a dtml-in tag. I would like the client to be able to custimize the maximum amount of text output they see, so i did something like the following:
<dtml-var "item['title']" size="getTitleLen()">
Where getTitleLen is a method which returns an integer of how many characters max the title is to be. However, when i have this dtml method rendered, i get the following error:
a size attribute was used in a var tag with a non-integer value.
Looks like you'll need to patch lib/python/DocumentTemplate/DT_Var.py to get this working.
326,328c326,331 < except: raise 'Document Error',( < '''a <code>size</code> attribute was used in a <code>var</code> < tag with a non-integer value.''') ---
except: try: size=atoi(str(md[size])) except: raise 'Document Error',( '''a <code>size</code> attribute was used in a <code>var</code> tag with a non-integer value.''')
After this patch, you can use normal numeric literals, or you can use values from the namespace.
Except that the indentation of the patch hasn't come out right :-(
The final code should look like this:
if have_arg('size'): size=args['size'] try: size=atoi(size) except: try: size=atoi(str(md[size])) except: raise 'Document Error',( '''a <code>size</code> attribute was used in a <code>var</code> tag with a non-integer value.''')
Narrative:
If the literal value of the attribute "size" doesn't easily parse into an integer, try looking up the value of the attribute "size" in the namespace, and see if that wants to be a number. If all that fails, give normal error message.
-- Steve Alexander Software Engineer Cat-Box limited
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Beutiful! Thank you very much! Is this something that will get put into the zope tree for future versions, or is this something that i'm going to need to send patch files out with my product for? sRp -- Scott Parish http://srparish.net
Scott Parish wrote:
Is this something that will get put into the zope tree for future versions, or is this something that i'm going to need to send patch files out with my product for?
Put it in the Zope collector, with your rationale, and the patch. http://classic.zope.org:8080/Collector I just skimmed through the 91 entries for "size attribute dtml-var", and I can't see it there already. -- Steve Alexander Software Engineer Cat-Box limited
Thus spake Steve Alexander (steve@cat-box.net):
Scott Parish wrote:
Is this something that will get put into the zope tree for future versions, or is this something that i'm going to need to send patch files out with my product for?
Put it in the Zope collector, with your rationale, and the patch.
http://classic.zope.org:8080/Collector
I just skimmed through the 91 entries for "size attribute dtml-var", and I can't see it there already.
-- Steve Alexander Software Engineer Cat-Box limited
Ah, so that is where bugs/patches go. Thanks again sRp -- Scott Parish http://srparish.net
participants (2)
-
Scott Parish -
Steve Alexander