Thank you so much, your suggestion to place the begin/end-block into the
subroutine, so it can call itself recursively with that:
% sub expand_tree { begin
<pre>DEBUG</pre>
% my $node = shift;
% foreach my $node_type (keys(%{ $node })) {
<div class="<%= $node_type %>">
<h2 class="service_tree_node_type"><%= $node_type.'s' %></h2>
<ul>
% foreach my $child (keys(%{ $node->{$node_type} })) {
<li><%= $child %></li>
%= expand_tree($node->{$node_type}->{$child}->{'subelements'});
% }
</ul>
</div>
% }
% end -> (@_); }
%
% layout 'default';
%
<div class="container">
<h1>Make yourself at home, <%= $self->session('user_email') %>!</h1>
%= expand_tree($service_tree);
</div>
Thank you!
среда, 10 сентября 2014 г., 14:01:38 UTC+3 пользователь Vladimir Melnik
написал:
>
> I've just tried to use begin/end too. It works fine even without "sub":
>
> % my $expand_tree = begin
> % my $node = shift;
> % foreach my $node_type (keys(%{ $node })) {
> <div class="<%= $node_type %>">
> <h2><%= $node_type.'s' %></h2>
> <ul>
> % foreach my $child (keys(%{ $node->{$node_type} })) {
> <li><%= $child %></li>
> % }
> </ul>
> </div>
> % }
> % end
> %
> % layout 'default';
> %
> <div class="container">
> <h1>Make yourself at home, <%= $self->session('user_email') %>!</h1>
> %= $expand_tree->($service_tree);
> </div>
>
> But I'll try your another recommendation (concerning '%=' instead of '%')
> now
>
> среда, 10 сентября 2014 г., 13:43:25 UTC+3 пользователь vitas написал:
>>
>> On 09/10/2014 12:36 PM, vitas wrote:
>> > Hi,
>> >
>> >> % layout 'default';
>> >> <div class="container">
>> >> <h1>Make yourself at home, <%= $self->session('user_email')
>> %>!</h1>
>> >> % expand_tree($service_tree);
>> > > ..
>> >
>> > Try:
>> >
>> > %= expand_tree($service_tree)
>>
>> And, dirty hack:
>>
>> % sub expand_tree { begin
>> <pre>DEBUG</pre>
>> % my $node = shift;
>> % foreach my $node_type (keys(%{ $node })) {
>> <div class="<%= $node_type %>">
>> <h2><%= $node_type.'s' %></h2>
>> <ul>
>> % foreach my $child (keys(%{ $node->{$node_type} })) {
>> <li><%= $child %></li>
>> % }
>> </ul>
>> </div>
>> % }
>> % end -> (@_) }
>>
>> vitas
>> @;;
>>
>
--
You received this message because you are subscribed to the Google Groups
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.