-
Notifications
You must be signed in to change notification settings - Fork 106
[FEATURE] Add f:format.cssVariables ViewHelper #1229
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
base: main
Are you sure you want to change the base?
[FEATURE] Add f:format.cssVariables ViewHelper #1229
Conversation
|
I’m wondering why we should include CSS in the HTML document. I think this viewhelper is more of a personal use case and shouldn’t be part of the fluid itself. |
|
I can see some use cases where this might be helpful, similarly to JSON formatting. I think it doesn't hurt to add this to Fluid, since it's a fairly simple implementation. But now that I think about it, the ViewHelper should probably do less: It should just create a list of variables from the specified array and return them in one line. This would also allow usage in inline |
|
@s2b so I remove the argument "selector" and remove the brackets? |
|
Or you leave it in but don't set a default and remove the brackets if it isn't set. Not sure which one is better. |
9559f1b to
e7249be
Compare
e7249be to
8a0b5cc
Compare
|
Heyho @s2b Thanks for review in advance. |
| * | ||
| * {someArray -> f:format.cssVariables()} | ||
| * | ||
| * ``["array","values"]`` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I missing something or does this example not belong here?
| * The css variable names are created from the array keys. | ||
| * You can add a custom prefix to the CSS variable name. | ||
| * | ||
| * By default, the variables are defined as `:root`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No longer correct. Maybe something like this instead?
Optionally, a CSS selector (e. g.
:root) can be supplied which will be wrapped around the CSS variables.
|
|
||
| public function initializeArguments(): void | ||
| { | ||
| $this->registerArgument('value', 'mixed', 'Input array which should be provided as CSS variables'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type is probably array here?
|
Thanks! Just some small adjustments, then it can go in. :) |
Issue #1228
Description
The new :html:
<f:format.cssVariables>ViewHelper provides an easy way to format array-structured Fluid data as CSS custom properties (variables). This is particularly useful for passing data from fluid variables to CSS, allowing for dynamic and easily maintainable theme styling.The ViewHelper recursively processes a given Fluid array, converting each key-value pair into a CSS variable. The array keys are transformed into CSS variable names (e.g.,
camelCaseKeybecomes--camelcasekey), and the corresponding values are used as the variable values. Only string values are rendered.Example
Fluid Template:
Generated CSS Output:
Impact
This new ViewHelper simplifies the process of creating dynamic and themable components. By allowing developers to pass data directly from Fluid to CSS, it reduces the need for complex workarounds or manual synchronization between backend data and frontend styles. This leads to cleaner, more maintainable code and makes it easier to implement features like user-customizable themes.