Dancer 1.3124 templates FOREACH not working as expected?by peter.pl (Novice)
|on Jun 21, 2014 at 06:49 UTC||Need Help??|
peter.pl has asked for the
wisdom of the Perl Monks concerning the following question:
By way of introduction, I'm a new user on the site and new to the Dancer framework, though I did spend some !quality time working with Django quirks at my last job so I'm not new to these frameworks in general. I'm porting a simple CLI Google Place miner into a simple web app, because then the user can run the queries herself and maybe I'll generate maps suitable for printing or something.
However, the included template parser doesn't seem to be handling arrays as expected using the <% FOREACH item IN array %> construct. I can't, for the life of me, figure out how to get it to work properly. I'm using Perl 5.16.2 with Dancer 1.3124 on OpenSuSE 12.3.
Here's the dispatch and template code
From that I know, passing the arrayref is correct. (Passing the array results in only the first item being printed.) I've dumped the read_file results and know that it's an array of lines. (Yeah, I know I'm unnecessarily using File::Slurp->read_file in a scalar context but I figured, what the heck...)
This results in one space-delimited line as if I had passed a scalar:
(That's the HTML from Firebug.) Originally it was supposed to be a group of checkboxes, and the result was the same except it was followed by one checkbox. I've tried it by defining the arrayref directly in the template, just like in the examples, and the results are same. It's just not working properly.
Am I doing something wrong? Should I try to extract keys from a hashref instead? Use Dancer2? I feel a forehead slap coming...