In a _layout.html file which I render to an HTML I have the following
<style type="text/css">
.btn-primary { background: #cb6532; }
</style>
Since I want to make the color dynamic, in a generator.py
template = self.env.get_template('_layout.html')
with open('public/index.html', 'w+', encoding='utf-8') as file:
html_and_css = template.render(
button_primary_color = "#cb6532"
)
file.write(html_and_css)
and changed the _layout.html to
<style type="text/css">
.btn-primary { background: {{ button_primary_color }}; }
</style>
Thing is, this way the color isn't applied, this is what I see in the generated file
<style type="text/css">
.btn-primary { background: ; }
</style>
How can that be done?
Edit
If I change the _layout.html to
<style type="text/css">
.btn-primary { background: "{{ button_primary_color }}"; }
</style>
then I'll get
<style type="text/css">
.btn-primary { background: "#cb6532"; }
</style>
which ofc doesn't apply the style.
question from:https://stackoverflow.com/questions/65933635/change-css-in-a-jinja2-template