building a Javascript array with TAL in ZPT
Hi everyone, I need to buid a javascript array of this form: var theArray = new Array("123|Beth","543|John","234|Ben","43|Leia","76|Steven","45|Rebecca","7686|Travis","3456|Kirk"); but by using TAL in a ZPT. The values come from a ZSQL method. It could look like this: var theArray = new Array( <span tal:repeat="array_elt container/reqZSQL3" tal:omit-tag=""> <span tal:replace="array_elt">1</span><span tal:condition="not:repeat/array_elt/end" tal:omit-tag="">, </span> </span>); but this is not working. (the ZSQL method contain the two columns of value) Someone have an idea? Thanks Etienne
Etienne Desgagné wrote:
Hi everyone,
I need to buid a javascript array of this form:
var theArray = new Array("123|Beth","543|John","234|Ben","43|Leia","76|Steven","45|Rebecca","7686|Travis","3456|Kirk");
but by using TAL in a ZPT. The values come from a ZSQL method. It could look like this:
var theArray = new Array( <span tal:repeat="array_elt container/reqZSQL3" tal:omit-tag=""> <span tal:replace="array_elt">1</span><span tal:condition="not:repeat/array_elt/end" tal:omit-tag="">, </span> </span>);
but this is not working. (the ZSQL method contain the two columns of value)
Someone have an idea?
I think you should access the two columns of return values individually, like: <span tal:replace='string:"${array_elt/id}|${array_elt/name}"' /> assuming the names of your two columns are id and name. By the way, the <tal> tag will not be executed within <script> tags. So you may have to use python script to generate your javascript code. -- HONG Yuan Homemaster Trading Co., Ltd. No. 601, Bldg. 41, 288 Shuangyang Rd. (N) Shanghai 200433, P.R.C. Tel: +86 21 55056553 Fax: +86 21 55067325 E-mail: hongyuan@homemaster.cn
Etienne Desgagné wrote:
Hi everyone,
I need to buid a javascript array of this form:
var theArray = new Array("123|Beth","543|John","234|Ben","43|Leia","76|Steven","45|Rebecca","7686|Travis","3456|Kirk");
but by using TAL in a ZPT. The values come from a ZSQL method. It could look like this:
var theArray = new Array( <span tal:repeat="array_elt container/reqZSQL3" tal:omit-tag=""> <span tal:replace="array_elt">1</span><span tal:condition="not:repeat/array_elt/end" tal:omit-tag="">, </span> </span>);
but this is not working. (the ZSQL method contain the two columns of value)
Someone have an idea?
ZPT is meant to generate [xml | (x)html]. Not css, javascripts, SQL or anything else (note that ZSQL methods use dtml as templating). For what you want, you may use a dtml method (first choice IMHO for non-html templating in Zope), or a python script (if the logic is too complex for dtml or if you don't want to learn dtml) that you call from the ZPT. My 2 cents... -- Bruno Desthuilliers Développeur bruno@modulix.org
Etienne Desgagné wrote:
var theArray = new Array( <span tal:repeat="array_elt container/reqZSQL3" tal:omit-tag=""> <span tal:replace="array_elt">1</span><span tal:condition="not:repeat/array_elt/end" tal:omit-tag="">, </span> </span>);
but this is not working. (the ZSQL method contain the two columns of value)
For better or for worse, ZPT's won't process anything inside a script tag. I'd generate it using a python script: js_template = ''' //whatever js you want ot be staticly generated %s ''' array = ','.join(container.reqZSQL3()) return js_template % array ...and then use them in your zpt as follows: <script tal:content="here/my_js_generator"/> cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
participants (4)
-
bruno modulix -
Chris Withers -
Etienne Desgagné -
Hong Yuan