You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
templ parsing error: for: expected nodes, but none were found
The error doesn't make much sense (sorry). After trial and error I figured out the issues seems to be the dynamic style attribute. From the docs it seems I should be able to use strings for dynamic HTML attributes:
I gotta say, it's quite an unintuitive design decision to be using dynamic styles via creating a CSS class. Pretty much any HTML templating language since the 90s has been able to just create dynamic inline styles.
It seems that the reason for this is to ensure sanitised CSS only in templ (at least that's my reading of the docs), but, how about abusing the templ.Attributes spreading to achieve it?
Thanks @pharrisee the attributes solution works well. Not sure why CSS would need to be sanitized to be honest.
Another point regarding the css functions is that creating <style> tags in the <body> tag is invalid HTML5. Try it out in the official HTML validator.
Finally, creating new classes for every variation of some values can be highly inefficient compared to inline styles. In my benchmark I got approx 3x performance with inline styles.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm having an issue where I need a dynamic
style
attribute string:But
templ generate
returns an error:The error doesn't make much sense (sorry). After trial and error I figured out the issues seems to be the dynamic
style
attribute. From the docs it seems I should be able to use strings for dynamic HTML attributes:What am I doing wrong?
Beta Was this translation helpful? Give feedback.
All reactions