<div dir="ltr"><div><div>Hi Atilla,<br><br></div>Thank you very much for the reply. I'm afraid that I am trying it but must have something wrong with my syntax.<br><br></div><div>This is how I display raw data.<br><br><% FOREACH ID IN MyHash.keys %><br><br><% MyHash.$<a href="http://ID.NAME">ID.NAME</a> %><br><br><% END %><br><br></div><div>But when I do:<br></div><div><br><select><br>[% FOREACH ID IN MyHash.Keys %]<br><option value="[% ID %]" >[% ID %]</option><br>[% END %]<br></select><br><br></div><div>It does not seem to work. Only '% ID %' appears.<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2015-08-21 11:02 GMT-05:00 Attila Bárdi <span dir="ltr"><<a href="mailto:attila.bardi@gmail.com" target="_blank">attila.bardi@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Hey,<div><br></div><div>in your view:</div><div><br></div><div><select …></div><div>[% FOREACH ent IN YourHash.keys %]</div><div><option value="[% ent %]" >[% ent %]</option></div><div>[% END %]</div><div></select></div><div><br></div><div>Dancer + Template Toolkit are pretty easy to use, simple and effective:)</div><div><div class="h5"><div><br></div><div><div><blockquote type="cite"><div>On 21 Aug 2015, at 17:41, Richard Reina <<a href="mailto:gatorreina@gmail.com" target="_blank">gatorreina@gmail.com</a>> wrote:</div><br><div><div dir="ltr"><div>Hi David,<br><br></div>I was able to get this code to work so thank you very much as it was very helpful. Now on to try and somehow figure out how I can get the hash refrence into my bootstrap drop down menu. Ughh...<br></div><div class="gmail_extra"><br><div class="gmail_quote">2015-08-19 22:13 GMT-05:00 David H <span dir="ltr"><<a href="mailto:untg99@gmail.com" target="_blank">untg99@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div>Hi Richard,<br><br></div>There are two ways that I get info into a page in Dancer/2.<br></div>The first is to use an Ajax call, something like this:<br>$("#llinktoclick").click(function(event) {<br> var DoggyName = $('#DoggyName').val();<br> <br> event.preventDefault(); // Important to ensure the link doesn't get submitted.<br><br> $.ajax({<br> method: "POST",<br> url: "/getDoggyDetails",<br> data: { Doggy: DoggyName } // Optional, will be sent through as POST data ( ie. params->{'Doggy'} ),<br></div><div> // you can also use the route, by doing url: "/getDoggyDetails" + '/' + DoggyName , instead<br></div><div> })<br> <br> .done(function( msg ) {<br> // Do something here like clear and append a status box.<br> $('#ResponseText').empty(); // clear <br> $('#ResponseText').append(msg); // append the return value from your POST call <br> });<br><br>});<br><br></div>Then in your .pm file:<br><br>post '/getDoggyDetails' => sub {<br> my $params = request->params;<br></div><div> my $doggyName = $params->{'Doggy'} || "Not entered"; # the || stops uninitialised value warnings in perl.<br></div><div> return "Please enter a doggy name" if $doggyName eq "Not entered";<br></div><div> # DO stuff here with $doggyName etc...<br></div> return "This is the completion message to tell you it is all done";<br><div>};<br><br><br></div><div>The second way, which is probably what you are more interested in, is to pass it directly from the route. With mysql you can probably do a straight fetchallhashref and then pass the response directly to the page, then iterate through the values with template toolkit.<br></div><div>With your route in the Dancer pm file:<br><br>any [ 'get', 'post' ] => '/pagetoLoad' => sub {<br><br></div><div> my $sql = "SELECT * FROM Doggies";<br></div><div> # mysql connection stuff etc...<br></div><div> # Put it into a hashref<br> # my $doggieRef = $sth->fetchall_hashref(['ID','DoggyTagID'])); # Double attribute version, not common<br> my $doggieRef = $sth->fetchall_hashref('ID'); # Normal, single attribute version<br><br></div><div> # The Ref should contain things like $doggieRef->{'1'}{'Name'} = "Rover"; because of the way we are iterating it through with Template Toolkit. <br></div><div> # I would also recommend Data::Dumper to see the contents of your query<br></div><div> my $dumperDoggieText = Dumper($doggieRef);<br></div><div> print "Doggy text from sql query is: $dumperDoggieText\n";</div><div> # And, the other important part, sending it to the page.<br> <br> template 'templateName.tt', {<br></div><div> 'Doggies' => $doggieRef, # Make sure 'Doggies' here is what you will iterate through on the page </div><div> 'Testing' => "This is text to test to make sure this will come through", # to test, use this like <% Testing %> on your template page<br>}, {};<br></div><div>};<br><br></div><div>Then using Template Toolkit, in your template file, you can do something like:<br><br><% FOREACH id IN Doggies.keys %><br><br><% Doggies.$id.Name %><br><br></div><div><% END %><br></div><div><br></div><div>And also do our little test just to make sure values are coming through.<br><br></div><div><% Testing %><br></div><div>Which should print out: "This is text to test to make sure this will come through" (without the quotes)<br><br></div><div>In the end Template Toolkit can be a bit confusing with Hashes but it does support Perl hashes very well and also nested attributes, (hashes of hashes etc...).<br><br></div><div>I don't have a complete '"working example" on hand but if there is anything confusing just let me know and if anyone else sees anything blatantly wrong, please shout out.<br></div><div><br></div><div>David<br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote"><span>On Thu, Aug 20, 2015 at 11:47 AM, Richard Reina <span dir="ltr"><<a href="mailto:gatorreina@gmail.com" target="_blank">gatorreina@gmail.com</a>></span> wrote:<br></span><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span><div dir="ltr"><div>Have been learning Dancer2 over the last few weeks and really like it. Wondering if someone can tell me how I can load data from a MySQL database into a dancer rendered page. I am comfortable writing SQL in perl via perl->DBI just don't have any idea how to bring the data from a fetch into a webpage so that I can display it directly on the page or load it into a dropdown menu. Any help is greatly appreciated.<br><br></div>Thanks<br></div>
<br></span>_______________________________________________<br>
dancer-users mailing list<br>
<a href="mailto:dancer-users@dancer.pm" target="_blank">dancer-users@dancer.pm</a><br>
<a href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users" rel="noreferrer" target="_blank">http://lists.preshweb.co.uk/mailman/listinfo/dancer-users</a><br>
<br></blockquote></div><br></div>
<br>_______________________________________________<br>
dancer-users mailing list<br>
<a href="mailto:dancer-users@dancer.pm" target="_blank">dancer-users@dancer.pm</a><br>
<a href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users" rel="noreferrer" target="_blank">http://lists.preshweb.co.uk/mailman/listinfo/dancer-users</a><br>
<br></blockquote></div><br></div>
_______________________________________________<br>dancer-users mailing list<br><a href="mailto:dancer-users@dancer.pm" target="_blank">dancer-users@dancer.pm</a><br><a href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users" target="_blank">http://lists.preshweb.co.uk/mailman/listinfo/dancer-users</a><br></div></blockquote></div><br></div></div></div></div><br>_______________________________________________<br>
dancer-users mailing list<br>
<a href="mailto:dancer-users@dancer.pm">dancer-users@dancer.pm</a><br>
<a href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users" rel="noreferrer" target="_blank">http://lists.preshweb.co.uk/mailman/listinfo/dancer-users</a><br>
<br></blockquote></div><br></div>