I have sort of a slideshow style website using HTML and flask, with each page featuring a previous and next button to toggle different pages. Since I want this to be dynamic, I use session objects. My problem, though, is that for the first and second slides, I don’t want the previous button to be there. I did some researching and found out I can use jinja to conditionally show the button, but I can’t get it to work.
{% if session["page_index"] == 0 || session["page_index"] == 1%}
<div>
{# Don't show previous button here #}
</div>
{% else %}
<a id="previous" href="/{{session["slides"][session["page"]-1] }}" class="buttons">Previous</a>
{% endif %}
The session object code inside the a tag has a red underline on the "-1," even though it works, and the "||" gives an error also. I’m a little new to coding so any help would be appreciated.
>Solution :
I’m a little confused by your question. There is one actual issue: the "||" symbol is not used in python to express an or statement, the word "or" is used. As for making the button conditionally visible, you don’t need to have any code in the if statement, and it won’t appear. If for some reason you still want the button to have a hitbox and functionality, you can just change the opacity.
{% if session["page_index"] == 0 or session["page_index"] == 1%}
<div style="opacity: 0%">
<a id="previous" href="/{{session["slides"][session["page"]-1] }}" class="buttons">Previous</a>
</div>
{% else %}
<a id="previous" href="/{{session["slides"][session["page"]-1] }}" class="buttons">Previous</a>
{% endif %}