Olaf Buwen | 1 Sep 10:48
Picon

Re: How do I use selected/checked ?

This template:

<select>
    <option
	petal:repeat="entry options"
        petal:attributes="value entry/lang; selected entry/selected"
        petal:content="entry/title"/>
</select>

with this code:
...
print $template->process(
    options => [
        {lang => "foo", title => "Foobar"},
        {lang => "bar", title => "Barbar", selected => 'selected'},
        {lang => "baz", title => "Bazbar"},
    ]
);

gives this output:
<select>
        <option value="foo" >Foobar</option>
	<option value="bar" selected="selected">Barbar</option>
	<option value="baz" >Bazbar</option>
</select>

It is not in the docs, but AFAIK it is part of the TAL spec
that an attribute is not set when the appropriate entry is missing.

I hope this helps
(Continue reading)

Josh Narins | 1 Sep 17:14

Re: Tree Tactics

> I've got a tree, with arbitrary depth, like..
> 
> {
>   text => 'This is the top',
>   sort => [5,3,7],
>   children =>
>     3 => {
>           text => 'This should be second',
>           sort => [4,6],
>           children {
>              4 => { text=>'a leaf',},
>              4 => { text=>'another leaf',},
>           },
>     5 => ...
>     7 => ...
>   }
> }
> 
> I hope you get the idea.
> 
> How do I get this to work in Petal?
> 
> I figure I should be able to do it with a single template.
> 
> myself.xml
> ==========
> 
> <table>
>   <tr>
>     <td petal:content="object/text">
(Continue reading)

Chris Croome | 1 Sep 17:19
Picon
Favicon

Re: Tree Tactics

Hi

On Thu 01-Sep-2005 at 11:14:21AM -0400, Josh Narins wrote:
> > 
> > I figure I should be able to do it with a single template.
> 
> No one has recursive tips?

With MKDoc, for things like the sitemap, which is made up of nested
<UL>s, we use an include file -- it's not a single template, I don't
know how you would do it with a single template, but it might well
be possible...

Chris

--

-- 
Chris Croome                               <chris@...>
web design                             http://www.webarchitects.co.uk/ 
web content management                               http://mkdoc.com/   

Raymond Barkhouse | 1 Sep 17:31

Re: How do I use selected/checked ?

On Thu, 2005-01-09 at 10:48 +0200, Olaf Buwen wrote:
> This template:
> 
> <select>
>     <option
> 	petal:repeat="entry options"
>         petal:attributes="value entry/lang; selected entry/selected"
>         petal:content="entry/title"/>
> </select>
> 
> with this code:
> ...
> print $template->process(
>     options => [
>         {lang => "foo", title => "Foobar"},
>         {lang => "bar", title => "Barbar", selected => 'selected'},
>         {lang => "baz", title => "Bazbar"},
>     ]
> );
> 
> gives this output:
> <select>
>         <option value="foo" >Foobar</option>
> 	<option value="bar" selected="selected">Barbar</option>
> 	<option value="baz" >Bazbar</option>
> </select>
> 

That's the same method I use for very dynamic forms. For just filling in
form variables from a database/Apache::Request->param/CGI->param though
(Continue reading)

Bruno Postle | 1 Sep 18:24
X-Face

Re: Tree Tactics

On Thu 01-Sep-2005 at 16:19 +0100, Chris Croome wrote:
> 
> With MKDoc, for things like the sitemap, which is made up of nested
> <UL>s, we use an include file -- it's not a single template, I don't
> know how you would do it with a single template, but it might well
> be possible...

The sitemap fragment that includes itself looks something like this:

  <?xml version="1.0"?>
  <li xmlns:petal="http://purl.org/petal/1.0/">
    <a
      href="#"
      petal:attributes="href child/URI"
      petal:content="child/Title"
    >Child Document Title</a>
    <ul
      petal:define="children child/Children"
      petal:condition="children"
      petal:repeat="child children"
    >
    <?include file="fragment.xml"?>
    </ul>
  </li>

Note that 'Children' is a method that returns a list of objects that
are already sorted.  We don't try to do the sorting in the template.

--

-- 
Bruno
(Continue reading)

Fergal Daly | 1 Sep 23:31
Picon

Re: Tree Tactics

You can create a custom modifier that takes a template name and a set of named arguments, it loads and executes the template, passing in the arguments. That's how I've done it in the past.

It's in the mailing list archives I think,

F

On 9/1/05, Josh Narins <josh <at> narins.net> wrote:
> I've got a tree, with arbitrary depth, like..
>
> {
>   text => 'This is the top',
>   sort => [5,3,7],
>   children =>
>     3 => {
>           text => 'This should be second',
>           sort => [4,6],
>           children {
>              4 => { text=>'a leaf',},
>              4 => { text=>'another leaf',},
>           },
>     5 => ...
>     7 => ...
>   }
> }
>
> I hope you get the idea.
>
> How do I get this to work in Petal?
>
> I figure I should be able to do it with a single template.
>
> myself.xml
> ==========
>
> <table>
>   <tr>
>     <td petal:content="object/text">
>      This is dummy text
>     </td>
>     <td petal:repeat="SOMETHING HERE">
>      <xi:include href="./myself.xml" />
>     </td>
>   </tr>
> </table>
>
> What should that repeat be? I can do it with "each:" but then I don't
> get any order. I want the order to be that as described in the sort
> array ref.
>
> How does anyone handle recursive trees?

No one has recursive tips?



Josh Narins | 2 Sep 13:47

Re: Tree Tactics

> On Thu 01-Sep-2005 at 16:19 +0100, Chris Croome wrote:
> > 
> > With MKDoc, for things like the sitemap, which is made up of nested
> > <UL>s, we use an include file -- it's not a single template, I don't
> > know how you would do it with a single template, but it might well
> > be possible...
> 
> The sitemap fragment that includes itself looks something like this:
> 
>   <?xml version="1.0"?>
>   <li xmlns:petal="http://purl.org/petal/1.0/">
>     <a
>       href="#"
>       petal:attributes="href child/URI"
>       petal:content="child/Title"
>     >Child Document Title</a>
>     <ul
>       petal:define="children child/Children"
>       petal:condition="children"
>       petal:repeat="child children"
>     >
>     <?include file="fragment.xml"?>
>     </ul>
>   </li>
> 
> Note that 'Children' is a method that returns a list of objects that
> are already sorted.  We don't try to do the sorting in the template.

Sorry for the confusion.

My own efforts would have worked had their not been bad data
in the database, which was resulting in a bad select, which 
made the tree "wrong" when displayed.

Recursively called templates work fine.

Josh Narins | 2 Sep 13:53

Extra Utils

Writing my own "greaterthan" => 'gt' and "greaterthanorequals" => 'gte'
Petal::Utils was trivial (thanks to the authors of Equal.pm).

How does the decision to get stuff in Utils get made?

tia,
Josh

Jonathan Vanasco | 3 Sep 23:18
Favicon

& in get href

petal seems to turn all & instances into &amp;

i tried using &amp; which is 'well formed xml'
no luck

then i tried changing the petal input/output formats
no luck

if i do
     tal:attributes="href structure string:a&b"

then its fine

my question is:
   must i do that?  will browsers handle &amp; well or will that  
screw up my get/post vars

Bruno Postle | 4 Sep 00:34
X-Face

Re: & in get href

On Sat 03-Sep-2005 at 17:18 -0400, Jonathan Vanasco wrote:
> 
> my question is:
>   must i do that?  will browsers handle &amp; well or will that  
> screw up my get/post vars

It's fine, browsers will do the right thing if given something like
this:

  <a href="http://example.com/foo?a=b&amp;c=d">click here!</a>

--

-- 
Bruno


Gmane