[Petal] Multiple conditions?

Ronald Hayden rhayden at apple.com
Sun Mar 9 13:05:41 GMT 2003


On Sunday, March 9, 2003, at 11:04  AM, jhiver at mkdoc.com wrote:

> In the (happy) event where you'd like to put some example on the site
> just gimme a should on the ML and I'll create an editor account for 
> you.

I'd be happy to provide some examples.  I should get code-reviewed on 
them, though, since I'm still a newbie.


> <section petal:repeat="chapter $book/chapters">
>
> Does this work at all? Using the $ sign is for inline stuff... Petal 
> must
> be pretty forgiving :-)

It is forgiving, and I vote for keeping it that way in this case!  I 
started out not using $ inside Petal attributes, but as soon as I did a 
presentation showing my department how this stuff worked, someone 
pointed out the "bug" in my template because I wasn't consistently 
using the $.  So I started putting it in for consistency -- and because 
once I'm done with the first pass, it will be non-programmers 
maintaining this, and it's not going to be fair to make them try and 
remember "For the same word, you put $ here but not over here..."

Secondly, after your comment I decided to go pull the extra $s out of a 
template...and of course I managed to pull one from an inline spot (an 
attribute) and break the template.  So maybe even programmers don't 
want to have to remember the rules!


> To come back to your question, Petal allows you to write your own
> modifiers. So the workaround would be to write a or: modifier...

Thanks -- I'll probably end up using that at some point.  However, 
having to work around the lack of an OR actually ended up with me 
learning more Petal and finding a better solution for this case.  I'm 
pretty happy with it, since it means that future templates can be made 
with no extra code.

The final results are along these lines (consider it my first example!):

<page petal:set="chapters $book/chaptersContainingNamedDescendants 
'Figure' 'CodeListing' 'Table'"
             petal:condition="true:$chapters">

<head1>Figures, Listings, and Tables</head1>

<section petal:repeat="chapter $chapters">

         <chapter_entry>
             <chapter_title internal-destination="$chapter/page_ref" 
petal:content="structure $chapter/name"></chapter_title >
             <chapter_page ref-id="$chapter/page_ref" />
         </chapter_entry>

         <entry petal:repeat="figure $chapter/namedDescendants 'Figure'">
             <entry_title internal-destination="$figure/page_ref" 
petal:content="structure $figure/name"></entry_title>
             <entry_page ref-id="$figure/page_ref" />
         </entry>

         <entry petal:repeat="listing $chapter/namedDescendants 
'CodeListing'">
             <entry_title internal-destination="$listing/page_ref" 
petal:content="structure $listing/name"></entry_title >
             <entry_page ref-id="$listing/page_ref" />
         </entry>

         < entry petal:repeat="table $chapter/namedDescendants 'Table'">
             <entry_title internal-destination="$table/page_ref" 
petal:content="structure $table/name"></entry_title>
             <entry_page ref-id="$table/page_ref" />
         </entry>

</section>
</page>

  -- Ron




More information about the Petal mailing list