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

`Str::template` does not work with placeholder containing a dot #1939

texnixe opened this issue Jul 22, 2019 · 1 comment


Copy link

commented Jul 22, 2019

Describe the bug
When a placeholder like {{ }} contains a dot, the template() method regards this as a query and returns no result.

Example code to reproduce the issue:

  1. Hook in plugin
    'hooks' => [
        'kirbytags:after' => function ($text, $data, $options) {
            $translations = $this->language()->translations();
            return Str::template($text, $translations);

In text file:

{{ }} is the best company in the world.

In language file, e.g. site/languages/en.php

    'translations' => [
        '' => 'Supercomp Ltd.'

Result: no string replacement takes place. The code works, however, with placeholders without the dot.

Expected behavior
Placeholders with dots should be replace because using dots is quite common to structure language variables.

Additional context
@distantnative proposed the following change in the template() method:

return (new Query($match[1], $data))->result() ?? $data[$query] ?? $fallback;

@distantnative distantnative self-assigned this Jul 22, 2019

@distantnative distantnative added this to the 3.2.3 milestone Jul 22, 2019

bastianallgeier added a commit that referenced this issue Jul 29, 2019


This comment has been minimized.

Copy link

commented Jul 29, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants
You can’t perform that action at this time.