0

I'd like to include a default template as a variable to pass it into a default case, like below:

<div class="row max-h-200 overflow-hidden">
    {% include 'blog/userprofile_deleted.html' as deleted_profile %}
    {{ user.profile.bio | safe | default:deleted_profile }}
</div>

Is this possible in django 3.2.9 ?

Currently I have to write out the default text as html in a single line:

<div class="row max-h-200 overflow-hidden">
    {{ user.profile.bio | safe | default:'<h4> Very long html string! </h4> <span>Comment as <b>you</b> with your own profile!</span><span>Create your Account at the <a href="#footer">bottom of the page</a>,or by visiting <a href="{% url "register" %}"><code>/register</code></a> !</span>' }}
</div>
Krabs
  • 3
  • 1
  • 4
  • If you need different block for not authenticated users use `if` like in this example https://docs.djangoproject.com/en/4.1/topics/auth/default/#users – Ivan Starostin Nov 13 '22 at 14:35
  • Hi @BrianObot, thanks for letting me know to restructure the question. I tried my best initally to have a minimal thread. What would you suggest me to add / edit for my question ? – Krabs Nov 14 '22 at 20:57
  • Hi @IvanStarostin, I know about if statements and `user.is_authenticated`, but in my example the `user` comes from another object query (`{% include "blog/userprofile_short.html" with user=post.author %}`) and the bio might be null (not blank or whitespace). – Krabs Nov 14 '22 at 20:59
  • IF user or bio is null THEN include default template or block ELSE the other template or block – Ivan Starostin Nov 15 '22 at 04:26
  • Thank you @IvanStarostin for trying to resolve my issue, but the question is still open: is it possible to store a template into a var to use for later. – Krabs Nov 16 '22 at 21:27

0 Answers0