Html class changing is failing - html

I am initializing icons based on different outcomes in Django template. Here is my code
{% if name == 'Euro' %}
<i class="fa fa-eur"></i>
{% else %}
<i class="fa fa-shopping-bag"></i>
{% endif %}
Problem is whatever the outcome is, icon class is remaining fa fa-shopping-bag . I have checked if/else conditional, it is working perfectly. What is the cause of this phenomenon? How can i solve this?

Related

what is ? in pagination hyper links

Hi im reading a book about django and in pagination template i see a ? but i do not know why is it there.I searched but got no answer.
Here is the template :
<div class="pagination">
<span class="step-links">
{% if page.has_previous %}
Previous
{% endif %}
<span class="current">
Page {{ page.number }} of {{ page.paginator.num_pages }}.
</span>
{% if page.has_next %}
Next
{% endif %}
</span>
</div>
what is the question mark in the address of page in ???
The ? basically represents a query parameter in the URL.
In many cases, the beginning of the query string is marked with a question mark and the various parameters that make up the query string are separated with an ampersand, but other syntaxes are also possible.
domain.com?parameter1=value1&parameter2=value2&parameter3=value3

Repeat string multiple times in Jekyll

How do you repeat string multiple times in Jekyll?
For eg: in Python, you can do "hello" * 5 to get 'hellohellohellohellohello'. In Jekyll is there an easier way of doing the same thing than this.
{% for i in (1..5) %}
Hello
{% endfor %}
Example
Say you want to display a star rating and you are using <i class="fa fa-star"></i> to display each star. So to display a 5 star rating you would do.
{% for i in (1..5) %}
<i class="fa fa-star"></i>
{% endfor %}
A single page may have many ratings displayed on it so you would be using several instances of that for loop.
This is the best way.
If your concern is about performance; then you don't need worry because Jekyll Liquid is precompiled into html anyway so the performance will only be affected at build time.

How can I disable the excerpt_link in octopress?

I wrote my posts and added <!-- more --> to where I want to stop the content from showing. After this, octopress shows a "read on" link, I want this not to show. I think this snippet (inside _includes/article.html file) is the key:
{% if excerpted == 'true' %}
<footer>
<a rel="full-article" href="{{ root_url }}{{ post.url }}">{{ site.excerpt_link }}</a>
</footer>
{% endif %}
I tried to delete this snippet and the link still shows. Tried to delete excerpt_link from `_config.ylm' and the html is still generated for the link.
This is the way to do it. Be sure to do it in sources/_includes/article.html and not within .themes/themeName.

Django Template: remove the buttons when session starts

I am trying to make a Login Authentication in Django. I have made sign in and sign up buttons in the upper navbar.
Now What I need to achieve is when I sign in to the application the redirection would take place and at that time session is checked and if the session has started then the sign in and sign up button disappears and the User ABC button comes at its place.
I am trying to do this with my code snipped here it is.
{% if request.session.loggedin %}
<li><a data-toggle="modal" href="#"><b>Hello Chitrank</b></a></li>
{% else %}
<li><a data-toggle="modal" href="#signup"><b>Sign Up</b></a></li>
<li><a data-toggle="modal" href="#signin"><b>Sign In</b></a></li>
{% endif %}
Please suggest me what to do , Am i using a wrong way to check the session or if there is some other way to do this then the solution is welcome.
{% if user.is_authenticated %}
is what you are looking for. https://docs.djangoproject.com/en/dev/ref/templates/api/#django-contrib-auth-context-processors-auth
also allows you to do this
<span>Welcome back {{ user.username }}!</span>
There is another solution on this, based on the logged in user (requires that you use django build in auth system).
You may access request.user.is_authenticated in your template and differentiate on its state (True is loggend in).
You may check whether you're logged in in the corresponding view and pass variable current_user to your template, then check:
{% if current_user %}
Hello, {{current_user.name}}
{% else %}
{# ... Display signin and signup buttons #}
{% endif %}

Django Template Whitespace

I'm at a loss as to what is happening here. I'm getting undesired spaces between span elements when I use indentation in the template. Ie:
<div>
<span class="empty-space"></span>
{% for dia in dias %}
<span class="{% cycle "dia-par" "dia-impar" %}">{{ dia }}</span>
{% endfor %}
</div>
So I'm forced to write the less readable form:
<div>
<span class="empty-space"></span>{% for dia in dias %}<span class="{% cycle "dia-par" "dia-impar" %}">{{ dia }}</span>{% endfor %}
</div>
To get the desired functionality. I already tried with margin-left/right:0px. and {%spaceless%}. Any Ideas what is going on?
The span is an inline element so white space is taken into an account.
Django has a spaceless tag which you can use to resolve this, as that removes the spaces between tags:
https://docs.djangoproject.com/en/3.2/ref/templates/builtins/#spaceless
It allows you to keep the template structure as is, but the output would be without the extra spaces.
You can also attack it from the CSS level, and set the span's display to inline-block.