Exactly what I want... with just one (deadly) problem. It yields double-encoded UTF8 :(
суббота, 6 мая 2017 г., 19:56:58 UTC+3 пользователь Stefan Adams написал: > > > On Thu, May 4, 2017 at 3:31 AM, Alex Povolotsky <[email protected] > <javascript:>> wrote: > >> I want to put part of the template in database; maybe someone has already >> done it and can share a recipie? > > > You probably just want to render inline > <http://www.google.com/url?q=http%3A%2F%2Fmojolicious.org%2Fperldoc%2FMojolicious%2FGuides%2FRendering%23Rendering-inline-templates&sa=D&sntz=1&usg=AFQjCNHIDc6au5O7yu_iiUJ8JgmC2gVTbQ> > . > > Fetch your template from your database and then render inline, something > like: > > sub action { > my $self = shift; > my $template = $self->pg->db->select('table', 'template', {id => > 123})->hash->{template}; > $self->stash(id => 123)->render(inline => $template); > } > > > Where in your database 'table' you have a record id=123, template="id: <%= > $id %>" > > Here's an inline helper that may help you to take it a step further and > embed that database template into an existing template. Not sure that I > did this well, but an initial test seems to work. > > helper inline => sub { > my $c = shift; > my $tmpl = shift; > my ($output, $format) = $c->app->renderer->render($c, {inline => $tmpl, > handler => "ep", format => "html", @_}); > return $output; > }; > > get '/' => sub { > my $c = shift; > $c->stash(id => 123, tmpl => $c->pg->db->select('table', 'template', {id > => 123})->render(inline => '<%= 1+1 %> <%= inline $tmpl %>'); > }; > > > > -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
