Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CONSTANTS not passed to Template #48

Open
assistcontrol opened this issue Nov 15, 2018 · 1 comment
Open

CONSTANTS not passed to Template #48

assistcontrol opened this issue Nov 15, 2018 · 1 comment

Comments

@assistcontrol
Copy link

It seems like CONSTANTS aren't being passed to the Template engine.

$app->plugin('tt_renderer' => {
    template_options => {
        CONSTANTS => { foo => 123 }
    }
}

template:
Foo is [% constants.foo %]


Expected: Foo is 123
Actual: Foo is

Is there something that I'm missing about passing in CONSTANTS?

@plicease
Copy link
Member

Interesting. It appears to have to do with the use of a customized Template::Provider subclass that is used by TtRenderer. I can reproduce the behavior with a simple script thusly:

use strict;
use warnings;
use Template;

my %config = (
  CONSTANTS => { foo => 123 },
);

$config{LOAD_TEMPLATES} = [ Template::Provider->new(%config) ];

my $tt = Template->new(\%config);

$tt->process(\"Foo is [% constants.foo %]\n");

when I run this I get:

helix% perl foo.pl 
Foo is 

if you look at the source code for TtRenderer you will see that it uses a Template::Provider subclass to handle some of the magic of finding templates in __DATA__ sections etc.

https://metacpan.org/source/PLICEASE/Mojolicious-Plugin-TtRenderer-1.60/lib/Mojolicious/Plugin/TtRenderer/Engine.pm#L66-68

Unfortunately the plugin does not work without the the Template::Provider subclass. I think this is a Template Toolkit issue, but I am happy to accept a patch which fixes it here if the problem is in TtRenderer.

plicease added a commit that referenced this issue Nov 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants