I'm trying to generate an html tag attribute in slim through content_for.
The output I would like to get is the something like :
body data-turbolinks="false"
What I've tried (that work) is the following :
from my view
- content_for(:body_attributes) do
=false
and from my app template
body data-turbolinks=(yield(:body_attributes) if content_for?(:body_attributes))
But I don't find the right syntax if I want to pass on the attribute AND its value from my content_for.
I've tried many things with no chance like :
body*{(yield(:body_attributes) if content_for?(:body_attributes)}
or
body[(yield(:body_attributes) if content_for?(:body_attributes)]
with something like this in my view :
- content_for(:body_attributes) do
= "#{'data-attribute=false'}"
Thanks for any idea !
Regarding comments :
# Template
body*{yield(:body_attributes) if content_for?(:body_attributes)}
# View
- content_for(:body_attributes) do
="data-turbolinks=>false"
OR
# Template
body*{yield(:body_attributes) if content_for?(:body_attributes)}
# View
- content_for(:body_attributes) do
data-turbolinks=false
Produces :
syntax error, unexpected modifier_if, expecting => s(({yield(:body_attributes) if content_for?(:body_attributes
# Template
body(yield(:body_attributes) if content_for?(:body_attributes))
# View
- content_for(:body_attributes) do
="data-turbolinks=>false"
OR
# Template
body(yield(:body_attributes) if content_for?(:body_attributes))
# View
- content_for(:body_attributes) do
data-turbolinks=false
Produces :
Slim::Parser::SyntaxError Expected attribute