<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Sorry, it is my mistake, I read as a select option:)<div class="">But the dropdown menu is working with the very same way!</div><div class="">FOREACH, add the entry, and END.</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 21 Aug 2015, at 18:02, Attila Bárdi <<a href="mailto:attila.bardi@gmail.com" class="">attila.bardi@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hey,<div class=""><br class=""></div><div class="">in your view:</div><div class=""><br class=""></div><div class=""><select …></div><div class="">[% FOREACH ent IN YourHash.keys %]</div><div class=""><option value="[% ent %]" >[% ent %]</option></div><div class="">[% END %]</div><div class=""></select></div><div class=""><br class=""></div><div class="">Dancer + Template Toolkit are pretty easy to use, simple and effective:)</div><div class=""><br class=""></div><div class=""><div class=""><blockquote type="cite" class=""><div class="">On 21 Aug 2015, at 17:41, Richard Reina <<a href="mailto:gatorreina@gmail.com" class="">gatorreina@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="">Hi David,<br class=""><br class=""></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 class=""></div><div class="gmail_extra"><br class=""><div class="gmail_quote">2015-08-19 22:13 GMT-05:00 David H <span dir="ltr" class=""><<a href="mailto:untg99@gmail.com" target="_blank" class="">untg99@gmail.com</a>></span>:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class=""><div class=""><div class=""><div class=""><div class="">Hi Richard,<br class=""><br class=""></div>There are two ways that I get info into a page in Dancer/2.<br class=""></div>The first is to use an Ajax call, something like this:<br class="">$("#llinktoclick").click(function(event) {<br class=""> var DoggyName = $('#DoggyName').val();<br class=""> <br class=""> event.preventDefault(); // Important to ensure the link doesn't get submitted.<br class=""><br class=""> $.ajax({<br class=""> method: "POST",<br class=""> url: "/getDoggyDetails",<br class=""> data: { Doggy: DoggyName } // Optional, will be sent through as POST data ( ie. params->{'Doggy'} ),<br class=""></div><div class=""> // you can also use the route, by doing url: "/getDoggyDetails" + '/' + DoggyName , instead<br class=""></div><div class=""> })<br class=""> <br class=""> .done(function( msg ) {<br class=""> // Do something here like clear and append a status box.<br class=""> $('#ResponseText').empty(); // clear <br class=""> $('#ResponseText').append(msg); // append the return value from your POST call <br class=""> });<br class=""><br class="">});<br class=""><br class=""></div>Then in your .pm file:<br class=""><br class="">post '/getDoggyDetails' => sub {<br class=""> my $params = request->params;<br class=""></div><div class=""> my $doggyName = $params->{'Doggy'} || "Not entered"; # the || stops uninitialised value warnings in perl.<br class=""></div><div class=""> return "Please enter a doggy name" if $doggyName eq "Not entered";<br class=""></div><div class=""> # DO stuff here with $doggyName etc...<br class=""></div> return "This is the completion message to tell you it is all done";<br class=""><div class="">};<br class=""><br class=""><br class=""></div><div class="">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 class=""></div><div class="">With your route in the Dancer pm file:<br class=""><br class="">any [ 'get', 'post' ] => '/pagetoLoad' => sub {<br class=""><br class=""></div><div class=""> my $sql = "SELECT * FROM Doggies";<br class=""></div><div class=""> # mysql connection stuff etc...<br class=""></div><div class=""> # Put it into a hashref<br class=""> # my $doggieRef = $sth->fetchall_hashref(['ID','DoggyTagID'])); # Double attribute version, not common<br class=""> my $doggieRef = $sth->fetchall_hashref('ID'); # Normal, single attribute version<br class=""><br class=""></div><div class=""> # The Ref should contain things like $doggieRef->{'1'}{'Name'} = "Rover"; because of the way we are iterating it through with Template Toolkit. <br class=""></div><div class=""> # I would also recommend Data::Dumper to see the contents of your query<br class=""></div><div class=""> my $dumperDoggieText = Dumper($doggieRef);<br class=""></div><div class=""> print "Doggy text from sql query is: $dumperDoggieText\n";</div><div class=""> # And, the other important part, sending it to the page.<br class=""> <br class=""> template 'templateName.tt', {<br class=""></div><div class=""> 'Doggies' => $doggieRef, # Make sure 'Doggies' here is what you will iterate through on the page </div><div class=""> 'Testing' => "This is text to test to make sure this will come through", # to test, use this like <% Testing %> on your template page<br class="">}, {};<br class=""></div><div class="">};<br class=""><br class=""></div><div class="">Then using Template Toolkit, in your template file, you can do something like:<br class=""><br class=""><% FOREACH id IN Doggies.keys %><br class=""><br class=""><% Doggies.$id.Name %><br class=""><br class=""></div><div class=""><% END %><br class=""></div><div class=""><br class=""></div><div class="">And also do our little test just to make sure values are coming through.<br class=""><br class=""></div><div class=""><% Testing %><br class=""></div><div class="">Which should print out: "This is text to test to make sure this will come through" (without the quotes)<br class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">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 class=""></div><div class=""><br class=""></div><div class="">David<br class=""></div><div class=""><br class=""></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote"><span class="">On Thu, Aug 20, 2015 at 11:47 AM, Richard Reina <span dir="ltr" class=""><<a href="mailto:gatorreina@gmail.com" target="_blank" class="">gatorreina@gmail.com</a>></span> wrote:<br class=""></span><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><div dir="ltr" class=""><div class="">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 class=""><br class=""></div>Thanks<br class=""></div>
<br class=""></span>_______________________________________________<br class="">
dancer-users mailing list<br class="">
<a href="mailto:dancer-users@dancer.pm" target="_blank" class="">dancer-users@dancer.pm</a><br class="">
<a href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users" rel="noreferrer" target="_blank" class="">http://lists.preshweb.co.uk/mailman/listinfo/dancer-users</a><br class="">
<br class=""></blockquote></div><br class=""></div>
<br class="">_______________________________________________<br class="">
dancer-users mailing list<br class="">
<a href="mailto:dancer-users@dancer.pm" class="">dancer-users@dancer.pm</a><br class="">
<a href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users" rel="noreferrer" target="_blank" class="">http://lists.preshweb.co.uk/mailman/listinfo/dancer-users</a><br class="">
<br class=""></blockquote></div><br class=""></div>
_______________________________________________<br class="">dancer-users mailing list<br class=""><a href="mailto:dancer-users@dancer.pm" class="">dancer-users@dancer.pm</a><br class=""><a href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users" class="">http://lists.preshweb.co.uk/mailman/listinfo/dancer-users</a><br class=""></div></blockquote></div><br class=""></div></div></div></blockquote></div><br class=""></div></body></html>