Acme-CPANModulesBundle-Import-MojoliciousAdvent-2018

 view release on metacpan or  search on metacpan

devdata/https_mojolicious.io_blog_2018_12_21_a-little-christmas-template-cooking_  view on Meta::CPAN


say $mt->render(<<~'EOF');
  % use Time::Piece;
  <div>
    % my $now = localtime;
    Time: <%= $now->hms %>
  </div>
  EOF
</code></pre>

<p>The lines with leading percent sings are Perl code. One of those lines loads a module, <a href="https://metacpan.org/pod/Time::Piece">Time::Piece</a>, and the other creates the variable <code>$now</code>. The <code>&lt;%= %&gt;</code> insert value...

<p>You can invert that so that the source of the values comes from outside of the template. Sometimes this is preferable to having too much logic in the presentation layer:</p>

<pre><code>use v5.26;
use Mojo::Template;

my $mt = Mojo::Template-&gt;new;

use Time::Piece;
my $now = localtime;



( run in 0.342 second using v1.01-cache-2.11-cpan-05162d3a2b1 )