[dancer-users] Delayed template processing
John Stoffel
john at stoffel.org
Fri Oct 16 16:05:02 BST 2015
Thanks for posting your example, this should be documented
somewhere... but I also wonder if you really just need to put a <div>
into your template and have your javascript just load more data from a
seperate route into that div which could then scroll, re-draw, or
whatever.
Basically, if you have a long running process, how would you handle
pagination of the results using your method? And what does your
view2.tt contain as well?
Joerg> Thanks to everyone involved I finally managed to get it done;
Joerg> For people with the same problem, here is an example for what I did,
Joerg> my $parameterhash;
Joerg> get '/routeA/:*?' => sub {
Joerg> my $id = params->{'id'};
Joerg> my $blub = params->{'blub'};
Joerg> delayed {
Joerg> my $tt = Template->new(
Joerg> {INCLUDE_PATH => "$path",
Joerg> WRAPPER => 'layout.tt',
Joerg> RELATIVE => 1,
Joerg> }) || die "Template error: $Template::ERROR\n";
Joerg> $tt->process('view.tt', {
Joerg> 'id' => $id,
Joerg> 'bla' => $blub
Joerg> };
Joerg> content $tt;
Joerg> done;
Joerg> ## Manual states from here on we can do whatever we want without intereferring with the stream
Joerg> $parameterhash =
Joerg> {
Joerg> 'id' => $id,
Joerg> 'bla' => $blub
Joerg> };
Joerg> };
Joerg> };
Joerg> get '/routeB/:*?' => sub {
Joerg> ## parameters are now fetched from the parameterhash reference
Joerg> my $id = $parameterhash->{'id'};
Joerg> my $blub = $parameterhash->{'bla'};
Joerg> # Do something from here on
Joerg> my $addition = "something";
Joerg> delayed {
Joerg> my $tt = Template->new(
Joerg> {INCLUDE_PATH => "$path",
Joerg> WRAPPER => 'layout.tt',
Joerg> RELATIVE => 1,
Joerg> }) || die "Template error: $Template::ERROR\n";
Joerg> $tt->process('view2.tt', {
Joerg> 'id' => $id,
Joerg> 'bla' => $blub
Joerg> 'addition' => $addition
Joerg> };
Joerg> content $tt;
Joerg> done;
Joerg> };
Joerg> In the template view.tt
Joerg> I simply added
Joerg> <script type="text/javascript">
Joerg> $(document).ready( function () {
Joerg> // Javascript URL redirection after 5 seconds
Joerg> setTimeout(function() {
Joerg> var str = window.location.href;
Joerg> var res = str.replace("routeA", "routeB");
Joerg> window.location.replace(res);
Joerg> }, 5000);
Joerg> });
Joerg> </script>
Joerg> which forwards to routeB,
Joerg> seems to work fine.
Joerg> The way I use it now I do not need delayed actually,
Joerg> but it doesn't hurt, so I keep for the moment.
Joerg> Thanks again to everybody!
Joerg> --joerg
Joerg> On 10/16/2015 01:51 PM, Clive Eisen wrote:
Joerg> Other people have told you how to do this
Joerg> In your template have callbacks to OTHER routes that return the rest of the data as and when it’s available
Joerg> If you insist use the same route and figure out from a param whether its the initial call or a callback
Joerg> As far as I can tell once you have served a template that request is closed
Joerg> --
Joerg> Clive Eisen
Joerg> GPG: 75056DD0
Joerg> On 16 Oct 2015, at 11:31, Joerg Fallmann <fall at tbi.univie.ac.at> wrote:
Joerg> To circumvent this I thought about forwarding to another route
Joerg> after processing a template,
Joerg> this should actually work around the update existing output problem,
Joerg> but it seems this is not possible either
Joerg> so I really got no idea how to proceed at the moment.
Joerg> --joerg
Joerg> On 10/16/2015 09:05 AM, Yitzchak Scott-Thoennes wrote:
Joerg> 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.
Joerg> But I don't know of such a template engine.
Joerg> _______________________________________________
Joerg> dancer-users mailing list
Joerg> dancer-users at dancer.pm
Joerg> http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
Joerg> _______________________________________________
Joerg> dancer-users mailing list
Joerg> dancer-users at dancer.pm
Joerg> http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
Joerg> _______________________________________________
Joerg> dancer-users mailing list
Joerg> dancer-users at dancer.pm
Joerg> http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
Joerg> _______________________________________________
Joerg> dancer-users mailing list
Joerg> dancer-users at dancer.pm
Joerg> http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
More information about the dancer-users
mailing list