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

[FEATURE] Scoped variables #1011

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

stefanr
Copy link

@stefanr stefanr commented Oct 18, 2024

Short intro

  • Extended the f:variable view helper to support a new backwards compatible scope attribute
    • Value: "global" (default) or "local"
  • When f:variable is used with scope="local" and is placed within a view helper opening a new variable scope via ScopedVariableProvider, the variable is only added to the local variable provider
  • Added a new f:scope view helper to simplify the use of local variables
    • It's actually similar to the f:alias view helper but without the need to initially declare variables

Example

<f:variable name="foo" value="World" />
<f:scope variables="{foo: 'Fluid', bar: 'Lorem'}">
  <f:variable name="baz" scope="local" value="Ipsum" />
  {bar} {baz} {foo}!
</f:scope>
Hello {foo}!

Output:

Lorem Ipsum Fluid!
Hello World!

After the scope {foo} is restored, {bar} and {baz} is removed.

@mbrodala
Copy link
Contributor

What is the exact usecase which cannot implemented with the current state?

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

Successfully merging this pull request may close these issues.

2 participants