Building multiple documents from fragments(objects).
Hello All, I have some newbie questions. I'm an experienced perl programmer trying to learn Zope/Python and am trying to do something I know must be possible, but am having a hard time wrapping my brain around this new way of doing things. I have a bunch of document fragments with the following structure: /docs fragment1 fragment2 fragment3 ... doc1/ index_html doc2/ index_html Currently, doc1/index_html and doc2/index_html have the following structure: <dtml-var standard_html_header> <h1><dtml-var title_or_id></h1> <div><h3>fragment1 title</h3> <ul> <li><dtml-var fragment1></li> </ul> </div> <div><h3>fragment2 title</h3> <ul> <li><dtml-var fragment2></li> </ul> </div> <div><h3>fragment3 title</h3> <ul> <li><dtml-var fragment3></li> </ul> </div> ... Is there a way that I can do something like this (warning: It's a clunky mix of perl and dtml): for my $f ( qw( fragment1 fragment2 fragment3 ) ) { <div><h3><dtml-var $f-title</h3> <ul> <li><dtml-var $f></li> </ul> </div> } I would prefer to do this entirely in dtml if at all possible (I need to show non-programmers how to do this if I can make it work and they don't wanna know about Python or Perl stuff). Failing that, is there a way I can do this generically enough that a designer could just use a dtml tag and pass the necessary values? Thanks for your input. Alan
Alan Young wrote:
Hello All,
I have some newbie questions.
I'm an experienced perl programmer trying to learn Zope/Python and am trying to do something I know must be possible, but am having a hard time wrapping my brain around this new way of doing things.
[snip]
Is there a way that I can do something like this (warning: It's a clunky mix of perl and dtml):
for my $f ( qw( fragment1 fragment2 fragment3 ) ) { <div><h3><dtml-var $f-title</h3> <ul> <li><dtml-var $f></li> </ul> </div> }
I would prefer to do this entirely in dtml if at all possible (I need to show non-programmers how to do this if I can make it work and they don't wanna know about Python or Perl stuff).
Failing that, is there a way I can do this generically enough that a designer could just use a dtml tag and pass the necessary values?
Thanks for your input.
Alan
Assuming they are DTML documents (if not, substitute your fragment object meta type) here is the DTML: <dtml-in expr="docs.objectValues('DTML Document')"> <div><h3><dtml-var name="title_or_id"></h3> <ul> <li><dtml-var name="sequence-item"></li> </ul> </div> </dtml-in> -- | Casey Duncan | Kaivo, Inc. | cduncan@kaivo.com `------------------>
Casey Duncan wrote:
<dtml-in expr="docs.objectValues('DTML Document')"> <div><h3><dtml-var name="title_or_id"></h3> <ul> <li><dtml-var name="sequence-item"></li> </ul> </div> </dtml-in>
Sorry, I guess I didn't explain myself well enough. I know how to do the above, what I want to do is specify a sub set of the fragments and in what order they should appear, so: <dtml-in "[fragment2, fragment1, fragment3]"> <div><h3><dtml-var name="title_or_id"></h3> <ul><li><dtml-var name="sequence-item"></li></ul> </div> </dtml-in> However the above gives me a syntax error: invalid syntax , for tag <dtml-in "[fragment1, fragment2]">, on line 7 of index_html <dtml-in "['fragment1', 'fragment2']"> doesn't give me an error but I just see ... <div><h3>Build From Loop</h3> <ul><li>fragment1</li></ul> </div> <div><h3>Build From Loop</h3> <ul><li>fragment2</li></ul> </div> ... Any further hints? And thanks for your help! :) Alan
You can use <dtml-in > to iterate over a list, have a look in the docs. So you could do: <dtml-in "[1,2,3]"> <dtml-var sequence-item> </dtml-in> Or if you have some way of differentiating fragment from other stuff: <dtml-in stuff> ... </dtml-in> Cheers. -- Andy McKay. ----- Original Message ----- From: "Alan Young" <alany@idiglobal.com> To: <zope@zope.org> Sent: Wednesday, April 04, 2001 9:23 AM Subject: [Zope] Building multiple documents from fragments(objects).
Hello All,
I have some newbie questions.
I'm an experienced perl programmer trying to learn Zope/Python and am trying to do something I know must be possible, but am having a hard time wrapping my brain around this new way of doing things.
I have a bunch of document fragments with the following structure:
/docs fragment1 fragment2 fragment3 ... doc1/ index_html doc2/ index_html
Currently, doc1/index_html and doc2/index_html have the following structure:
<dtml-var standard_html_header> <h1><dtml-var title_or_id></h1>
<div><h3>fragment1 title</h3> <ul> <li><dtml-var fragment1></li> </ul> </div>
<div><h3>fragment2 title</h3> <ul> <li><dtml-var fragment2></li> </ul> </div>
<div><h3>fragment3 title</h3> <ul> <li><dtml-var fragment3></li> </ul> </div>
...
Is there a way that I can do something like this (warning: It's a clunky mix of perl and dtml):
for my $f ( qw( fragment1 fragment2 fragment3 ) ) { <div><h3><dtml-var $f-title</h3> <ul> <li><dtml-var $f></li> </ul> </div> }
I would prefer to do this entirely in dtml if at all possible (I need to show non-programmers how to do this if I can make it work and they don't wanna know about Python or Perl stuff).
Failing that, is there a way I can do this generically enough that a designer could just use a dtml tag and pass the necessary values?
Thanks for your input.
Alan
_______________________________________________ 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 )
Andy McKay wrote:
<dtml-in "[1,2,3]"> <dtml-var sequence-item> </dtml-in>
Or if you have some way of differentiating fragment from other stuff:
<dtml-in stuff> ... </dtml-in>
See my other post about the first one (<dtml-in "[1,2,3]">). I'm not sure what you mean about the <dtml-in stuff> comment though. Alan
Sorry got cut off sending the email. If the fragments are say objects of a certain type you can objectValues as Casey suggested... -- Andy McKay. ----- Original Message ----- From: "Alan Young" <alany@idiglobal.com> To: "Andy McKay" <andym@ActiveState.com> Cc: <zope@zope.org> Sent: Wednesday, April 04, 2001 10:33 AM Subject: Re: [Zope] Building multiple documents from fragments(objects).
Andy McKay wrote:
<dtml-in "[1,2,3]"> <dtml-var sequence-item> </dtml-in>
Or if you have some way of differentiating fragment from other stuff:
<dtml-in stuff> ... </dtml-in>
See my other post about the first one (<dtml-in "[1,2,3]">). I'm not sure what you mean about the <dtml-in stuff> comment though.
Alan
participants (3)
-
Alan Young -
Andy McKay -
Casey Duncan