I'm trying to integrate this snippet into our Django project:
It's just custom HTML
and CSS
for messages.
The html
looks like this:
<div class="bs-calltoaction bs-calltoaction-success">
<div class="row">
<div class="col-md-9 cta-contents">
<h1 class="cta-title">Its a Call To Action</h1>
<div class="cta-desc">
<p>Describe the action here.</p>
<p>Describe the action here.</p>
<p>Describe the action here.</p>
</div>
</div>
<div class="col-md-3 cta-button">
<a href="#" class="btn btn-lg btn-block btn-default">Go for It!</a>
</div>
</div>
</div>
So if I want to integrate it with messages framework, I can do:
{% for message in messages %}
<div class="bs-calltoaction bs-calltoaction-{{ message.tags }}">
<div class="row">
<div class="col-md-9 cta-contents">
{{ message }}
</div>
<div class="col-md-3 cta-button">
<a href="#" class="btn btn-lg btn-block btn-default">Go for It!</a>
</div>
</div>
</div>
{% endfor %}
But I would like to specify header <h1>
and list of sub-messages <p>
so I need to add to message something like dictionary which can hold additional attributes like {'title':'This is a title','submessages':[1,2,3]}
so I can do:
{% for message in messages %}
<div class="bs-calltoaction bs-calltoaction-{{ message.tags }}">
<div class="row">
<div class="col-md-9 cta-contents">
<h1 class="cta-title">{{ message.title }}</h1>
<div class="cta-desc">
<p>{{ message.submessages.0 }}</p>
<p>{{ message.submessages.1 }}</p>
</div>
</div>
<div class="col-md-3 cta-button">
<a href="#" class="btn btn-lg btn-block btn-default">Go for It!</a>
</div>
</div>
</div>
{% endfor %}
Is it possible using Django messages? Or would you suggest another approach? I can pass such variables into the context but I would like to use messages if possible.
extra_tags
attribute is a string and not a dict. It's almost impossible to pass structured data this way. I don't understand this choice. – Intransigeance