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

Mustache engine is treating some data as variables and replacing with with empty string #414

Open
shkhalid opened this issue Mar 19, 2024 · 1 comment

Comments

@shkhalid
Copy link

$mustache = new \Mustache_Engine();
$variables = [
    'first_name' => 'Jackie',
    'last_name' => 'Chain',
];
        
dd($mustache->render('<a href="{{first_name}}" >{{last_name </a>}}', $variables));

In this case my output should be <a href="Jackie" >{{last_name </a>}} but now the result is <a href="Jackie" >

@bobthecow
Copy link
Owner

i'm not sure if it's a typo or if you intended it this way, but {{last_name </a>}} is a variable. it's just undefined. per the mustache spec, undefined variables are replaced with empty strings.

<?php

require_once __DIR__ . '/vendor/autoload.php';

$mustache = new \Mustache_Engine();
$variables = [
    'first_name' => 'Jackie',
    'last_name' => 'Chain',
    'last_name </a>' => 'wat',
];

echo $mustache->render('<a href="{{first_name}}" >{{last_name </a>}}', $variables);

… results in <a href="Jackie" >wat

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