Last active
August 29, 2015 14:17
-
-
Save deserted/5b30d3c54e79692aaafc to your computer and use it in GitHub Desktop.
Trouble iterating
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Helper Definition | |
$app->helper('blog.getCategories' => | |
sub { | |
my $self = shift; | |
my @cats = $self->db->resultset('BlogCategory')->all; | |
my @categories = map +{ id => $_->catid, name => $_->catname }, @cats; ## catid and catname both in DBIx::Class schema def | |
$self->app->log->debug(Dumper(\@categories)); | |
return wantarray ? @categories : \@categories; | |
} | |
); | |
## Dumper returns | |
$VAR1 = [ | |
{ | |
'id' => '1', | |
'name' => 'news' | |
} | |
]; | |
## shoved into stash then rendered | |
sub ajaxAddBlogPost { | |
my $self = shift; | |
$self->stash(postcats => $self->blog->getCategories); | |
$self->render(template => 'admin/page/createpost'); | |
} | |
## TEmplate section (using template toolkit with Mojolicious::Plugin::TtRenderer) | |
<label>Category | |
<select name="postcategory"> | |
[% FOREACH cat IN postcats %] | |
<option value="[% cat.id %]">[% cat.name %]</option> | |
[% END %] | |
</select> | |
</label> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment