[dancer-users] Delayed template processing

Joerg Fallmann fall at tbi.univie.ac.at
Fri Oct 16 14:11:45 BST 2015


Thanks to everyone involved I finally managed to get it done;

For people with the same problem, here is an example for what I did,

my $parameterhash;
get '/routeA/:*?' => sub {
     my $id = params->{'id'};
     my $blub = params->{'blub'};
     delayed {
        my $tt = Template->new(
           {INCLUDE_PATH => "$path",
            WRAPPER  => 'layout.tt',
            RELATIVE => 1,
           }) || die "Template error: $Template::ERROR\n";
        $tt->process('view.tt', {
             'id' => $id,
             'bla' => $blub
         };
     content $tt;
     done;
## Manual states from here on we can do whatever we want without 
intereferring with the stream
     $parameterhash =
         {
             'id' => $id,
             'bla' => $blub
         };
     };
};

get '/routeB/:*?' => sub {
## parameters are now fetched from the parameterhash reference
     my $id = $parameterhash->{'id'};
     my $blub = $parameterhash->{'bla'};

# Do something from here on
       my $addition = "something";
     delayed {
        my $tt = Template->new(
           {INCLUDE_PATH => "$path",
            WRAPPER  => 'layout.tt',
            RELATIVE => 1,
           }) || die "Template error: $Template::ERROR\n";
        $tt->process('view2.tt', {
             'id' => $id,
             'bla' => $blub
             'addition' => $addition
         };
     content $tt;
     done;
};

In the template view.tt
I simply added

<script type="text/javascript">
     $(document).ready( function () {
// Javascript URL redirection after 5 seconds
     setTimeout(function() {
         var str = window.location.href;
         var res = str.replace("routeA", "routeB");
     window.location.replace(res);
     }, 5000);
     });
</script>

which forwards to routeB,
seems to work fine.

The way I use it now I do not need delayed actually,
but it doesn't hurt, so I keep for the moment.

Thanks again to everybody!

--joerg


On 10/16/2015 01:51 PM, Clive Eisen wrote:
> Other people have told you how to do this
>
> In your template have callbacks to OTHER routes that return the rest of the data as and when it’s available
>
> If you  insist use the same route and figure out from a param whether its the initial call or a callback
>
> As far as I can tell once you have served a template that request is closed
>
> --
> Clive Eisen
> GPG: 75056DD0
>
>
>
>
>
>
>> On 16 Oct 2015, at 11:31, Joerg Fallmann <fall at tbi.univie.ac.at> wrote:
>>
>> To circumvent this I thought about forwarding to another route
>> after processing a template,
>> this should actually work around the update existing output problem,
>> but it seems this is not possible either
>> so I really got no idea how to proceed at the moment.
>>
>> --joerg
>>
>> On 10/16/2015 09:05 AM, Yitzchak Scott-Thoennes wrote:
>>> For this to work, you'd either need a template engine that is tightly integrated into Dancer or a streaming template engine (that would call a callback to call content as it got chunks) with the ability to loop over iterators or trigger callbacks to get more data to format.  Though I guess you could use a normal template loop over a tied array too.
>>>
>>> But I don't know of such a template engine.
>>>
>>>
>>>
>>> _______________________________________________
>>> dancer-users mailing list
>>>
>>> dancer-users at dancer.pm
>>> http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
>> _______________________________________________
>> dancer-users mailing list
>> dancer-users at dancer.pm
>> http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
>
>
> _______________________________________________
> dancer-users mailing list
> dancer-users at dancer.pm
> http://lists.preshweb.co.uk/mailman/listinfo/dancer-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.preshweb.co.uk/pipermail/dancer-users/attachments/20151016/e350ccbf/attachment.html>


More information about the dancer-users mailing list