0

I am using twig Pattern Lab includes with the longhand syntax (needed for integration reasons), aka {% include "@atoms/path/to/pattern.twig" %}.

If I have variables defined in a pattern, and then include that pattern in another pattern, the included pattern's variables are set to null, unless I pass in a new context with with.

For example:

my-atom

<p>{{ myvar }}</p> {# myvar is set when viewing my-atom directly #}

my-molecule

<div>{% include "@atoms/my-atom/my-atom.twig" %}</div> {# Prints an empty <p> tag #}

<div>{% include "@atoms/my-atom/my-atom.twig" with { myvar: "Hello!" } %}</div> {# Prints "<p>Hello!</p>" #}

I would expect the variables from the molecule to flow down to the atom, falling back to the atom's values if the variable isn't defined in the molecule, similar to how the short hand syntax works (aka, {% include "atoms-my-atom" %}).

Is this a feature? A bug? Is there something I'm missing?

Thanks so much in advance!

4

1 回答 1

1

据我所知,它正在按预期工作,至少在 Symfony 上它是这样工作的,我不知道它背后的原因。这就是为什么我更喜欢在我的控制器中渲染这些部分视图并将它们作为变量传递给主视图。

于 2016-12-01T21:12:33.917 回答