in reply to How do you use Template Toolkit with Dancer2?

Hi, everyone! I have a related question, the answer to which may be of some use to others. I have configured template_toolkit, and it seem to work, but I am running into an issue with UTF8 encoding. E.g.: if in the template I write 'François' the 'ç' is rendered correctly. However if I add % name % and assign name => 'François' in a route, the 'ç' is rendered as 'ħ'. Does anyone know how to remedy this? Thanks in advance...
  • Comment on Re: How do you use Template Toolkit with Dancer2?

Replies are listed 'Best First'.
Re^2: How do you use Template Toolkit with Dancer2?
by hippo (Archbishop) on Apr 21, 2022 at 21:42 UTC

    You have not mentioned Dancer2 at all, so I can only assume that part is irrelevant. In which case, here is my SSCCE:

    #!/usr/bin/env perl use strict; use warnings; use utf8; use Template; my $tt = Template->new; my $name = 'François'; my $ttext = <<EOT; As a literal: François As an interpolated variable: $name As a template variable: [% name %] EOT $tt->process (\$ttext, { name => $name });

    🦛

      Thank you for your quick response. Yes, I am investigating Dancer 2 to use as a replacement for the venerable CGI I've been using for many years. So my question is in context of Dancer 2. I am still in the early stages of familiarizing myself with it. Any suggestions would be greatly appreciated.
Re^2: How do you use Template Toolkit with Dancer2?
by choroba (Cardinal) on Apr 21, 2022 at 21:30 UTC
    What encoding do you save the source code in? Do you use utf8 to tell Perl your source code uses UTF-8?

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
      Thanks for your response. Yes I do. I think it might be something to do with interpolation.
        I tried it, it displays correctly in my browser. Are you sure your source code is saved in UTF-8?

        Also, in config.yml, yo need to specify

        charset: "UTF-8"

        map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]