-
Hi! I'm trying to create a custom Antlers tag that appends a new variable to its current local rendering context. Is this possible? I've tried appending to the context as well as the cascade. Neither seem to get picked up for use by the surrounding code. Use case: a {{# The `links` variable is empty here #}}
{{# The `capture` tag should set the value of the `links` variable from inside the tag handler #}}
{{ capture:links }}
{{ if email }} <a href="mailto:{{ email }}">E-Mail</a> {{ /if }}
{{ if cv }} <a href="{{ cv:url }}" download>CV</a> {{ /if }}
{{ /capture:links }}
{{# The `links` variable should be defined here #}}
{{ if links }} {{# do something with the html #}} {{ /if }} I'm struggling with the last part: putting the captured output into a variable that can be used further down after the custom tag. The This is the class Capture extends Tags
{
public function wildcard($varname)
{
$content = $this->parse();
$this->context[$varname] = $content;
Cascade::instance()->set($varname, $content);
}
} The current workaround is to reach into the cascade with a PHP override, but that doesn't feel very idiomatic... {{? if (\Statamic\Facades\Cascade::get('links')) { /* */ } ?}} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
that should work, is it possible you have a variable called Can you please confirm by taking out your tag and doing a Also, what version are you on? |
Beta Was this translation helpful? Give feedback.
that should work, is it possible you have a variable called
links
already there?Can you please confirm by taking out your tag and doing a
dump
to see if there's alinks
in there?Also, what version are you on?