I have a category called "tachartasan" which I have excluded from my index page however the posts in this category are still being counted in the pagination which is currently set to 10 posts per page.
7 of my most recent posts have been in the tachartasan category and it has resulted in my front page showing only 3 posts total.
<div class="container">
{% for post in paginator.posts %}
{% unless post.categories contains 'tachartasan' %}
<div class="row">
<div class="col-md-3">
<img src="{{ post.image }}" class="index-image">
</div>
<div class="col-md-9">
<h5 class="post-title">{{ post.title }}</h5>
{% if post.author %}
<p class="text-muted">{{ post.date | date: "%Y-%m-%d" }} le {{ post.author }}</p>
{% else %}
<p class="text-muted">{{ post.date | date: "%Y-%m-%d" }} le Crìstean MacMhìcheil</p>
{% endif %}
{{ post.excerpt }}
</div>
</div>
<hr/>
{% endunless %}
{% endfor %}
<!-- Pagination -->
<nav>
<ul class="pagination justify-content-center pagination-lg">
{% if paginator.next_page %}
<li class="page-item">
<a class="page-link" href="{{ site.baseurl }}/duilleag-{{paginator.next_page}}">
<i class="fas fa-arrow-left"></i>
</a>
</li>
{% else %}
<li class="page-item disabled">
<a class="page-link" href="{{ site.baseurl }}/">
<i class="fas fa-arrow-left"></i>
</a>
</li>
{% endif %}
<li class="page-item disabled">
<a class="page-link" href="{{ site.baseurl }}/">
Duilleag {{ paginator.page }} / {{ paginator.total_pages }}
</a>
</li>
{% if paginator.previous_page %}
{% if paginator.page == 2 %}
<li class="page-item">
<a class="page-link" href="{{ site.baseurl }}/">
<i class="fas fa-arrow-right"></i>
</a>
</li>
{% else %}
<li class="page-item">
<a class="page-link" href="{{ site.baseurl }}/duilleag-{{paginator.previous_page}}">
<i class="fas fa-arrow-right"></i>
</a>
</li>
{% endif %}
{% else %}
<li class="page-item disabled">
<a class="page-link" href="{{ site.baseurl }}/">
<i class="fas fa-arrow-right"></i>
</a>
</li>
{% endif %}
</ul>
</nav>
</div>
I don't want the hidden "tachartasan" posts to be counted as part of the 10 posts per page.
Adding this line to the front matter of my excluded posts solved it. They are hidden on the index page and no longer counted against the pagination limit and are still visible on the specific category page.
hidden: true
Related
{% for category in categories %}
{% if request.get_full_path == '/?category={{category.0}}' %}
{{ category.0 }}
<li class="nav-item active">
<span class="sr-only">(current)</span>
<a class="nav-link" href="/?category={{ category.0 }}">{{ category.1 }}</a>
</li>
{% else %}
{{request.get_full_path}}
/?category={{category.0}}
<li class="nav-item">
<span class="sr-only">(current)</span>
<a class="nav-link" href="/?category={{ category.0 }}">{{ category.1 }}</a>
</li>
{% endif %}
{% endfor %}
I want to highlight navigation buttons, but {% if %} statement can't see {{category.0}} expression inside.
Can I use {{}} inside {% if %} statement in jinja?
No you can use your return variable in {% if %}
Without {{}}
stack community I'm completely an amateur in HTML, Liquid, Adx, in short programming and applying logic, don't have great understanding.
Im not sure why the <span> Test2 </span> is appearing 2x, as you can see from the image,
I want to achieve the following, Test2 new name? as one text and the left Test2 don't want it to be displayed. Please advise.
{% assign homeurl = website.adx_partialurl %}
<div class="navbar navbar-inverse navbar-static-top" role="navigation">
<div class="container">
<div id="navbar" class="navbar-collapse collapse">
{% assign primary_nav = weblinks["Primary Navigation"] %}
{% if primary_nav %}
<div class="data-weblinks-maxdepth="">
<ul class="nav navbar-nav weblinks" role="menubar">
{% for link in primary_nav.weblinks %}
<li role="none" class="weblink {% if sublinks.size > 0 %} dropdown{% endif %}">
<a role="menuitem" aria-label="{{ link.name | escape }}" {%- if link.tooltip %} title="{{ link.tooltip | escape }}"
{% endif %}>
<span> Test2 </span>
{%- unless link.display_image_only -%}
{{ link.name | escape }}
{%- endunless -%}
</a>
</li>
{% endfor %}
</ul>
{% editable primary_nav %}
</div>
{% endif %}
</div>
</div>
</div>
To change the name of the link and perhaps add something in front of it all you have to do is add something into the if clause like below:
{% assign homeurl = website.adx_partialurl %}
<div class="navbar navbar-inverse navbar-static-top" role="navigation">
<div class="container">
<div id="navbar" class="navbar-collapse collapse">
{% assign primary_nav = weblinks["Primary Navigation"] %}
{% if primary_nav %}
<div class="data-weblinks-maxdepth="">
<ul class="nav navbar-nav weblinks" role="menubar">
{% for link in primary_nav.weblinks %}
<li role="none" class="weblink {% if sublinks.size > 0 %} dropdown{% endif %}">
<a role="menuitem" aria-label="{{ link.name | escape }}" {%- if link.tooltip %} title="{{ link.tooltip | escape }}"{% endif %}>
{%- unless link.display_image_only -%}
Text 2 {{ link.name | escape }}
{%- endunless -%}
</a>
</li>
{% endfor %}
</ul>
{% editable primary_nav %}
</div>
{% endif %}
</div>
</div>
</div>
I don't get it, If I remove the last <li> I'm not getting this error, here's my HTML,
I know I'm not closing a "if" tag correctly or something, the only solution for me is to remove the last last <li>
{% if request.get_full_path != "/addAssest/" and request.user.is_authenticated
%}
<div class="sidebar" style="height: 35%">
<div class="sidebar-wrapper">
<div class="logo">
<a
target="_blank"
href="https://www.creative-tim.com/product/black-dashboard-django"
class="simple-text logo-mini"
>
CC
</a>
<a
target="_blank"
href="https://www.creative-tim.com/product/black-dashboard-django"
class="simple-text logo-normal"
>
Crypto Castle
</a>
</div>
<ul class="nav">
<li class="{% if 'index' in segment %} active {% endif %}">
<a href="/">
<i class="tim-icons icon-chart-pie-36"></i>
<p>Dashboard</p>
</a>
</li>
<li class="{% if 'page-user' in segment %} active {% endif %}">
<a href="{% url 'profilePage' %}">
<i class="tim-icons icon-single-02"></i>
<p>User Profile</p>
</a>
</li>
<li class="{% if 'logout' in segment %} active {% endif %}">
<a href="{% url 'logout' %}">
<i class="tim-icons icon-user-run"></i>
<p>Logout</p>
</a>
</li>
</ul>
</div>
</div>
{% endif %}
Django template does not support multiline tags and tag escape tags as stated in this Ticket
You should edit your code :
{% if request.get_full_path != "/addAssest/" and request.user.is_authenticated
%}
to
{% if request.get_full_path != "/addAssest/" and request.user.is_authenticated %}
Note that most HTML linter will try to break your template tag so it is best to deactivate it
I have a view.py product_list:
...
from django.shortcuts import render, get_object_or_404
from .models import ProductCategory, Product, ProductDetail, ProductSpecialCategory
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
...
def product_list(request, category_slug=None, ):
category = None
categories = ProductCategory.objects.all()
object_list = Product.objects.filter(available=True, is_active=True)
if category_slug:
category = get_object_or_404(ProductCategory, slug=category_slug)
object_list = object_list.filter(category=category)
paginator = Paginator(object_list, 1)
page = request.GET.get('page')
try:
products = paginator.page(page)
except PageNotAnInteger:
products = paginator.page(1)
except EmptyPage:
products = paginator.page(paginator.num_pages)
return render(request, 'shop/products/list_by_category/product_list.html', {'category': category,
'categories': categories,
'products': products,
})
Based on this handler, I did pagination.html:
<nav aria-label="pagination" class="pagination_area">
<ul class="pagination">
{% if page.has_previous %}
<li class="page-item next">
<a class="page-link" href="?page={{ page.previous_page_number }}">
<i class="fa fa-angle-left" aria-hidden="true"></i>
</a>
</li>
{% endif %}
{% for i in page.paginator.page_range %}
{% if page.number == i %}
<li class="page-item focused"><a class="page-link" href="?page={{ i }}">{{ i }}</a></li>
{% elif i > page.number|add:'-1' and i < page.number|add:'1' %}
{% else %}
<li class="page-item"><a class="page-link" href="?page={{ i }}">{{ i }}</a></li>
{% endif %}
{% endfor %}
{% if page.has_next %}
<li class="page-item next">
<a class="page-link" href="?page={{ page.next_page_number }}">
<i class="fa fa-angle-right" aria-hidden="true"></i>
</a>
</li>
{% endif %}
</ul>
On the interface, I get the **result**:
I would like to organize in such a way that:
Show only three pages, the first of which is the previous one, the second is the current, the third is the next. And what is not included in this range are hidden by ellipses, for example.:
I change pagination.html. Please try this.
<nav aria-label="pagination" class="pagination_area">
<div class="row">
{% if page.end_index > 0 %}
<div class="col-sm-12 col-md-5 d-none d-md-block">
<p>Showing {{ page.start_index }} to {{ page.end_index }} of {{ page.paginator.count}}.</p>
</div>
{% endif %}
{% if page.paginator.num_pages > 1 %}
<div class="col-sm-12 col-md-7 dataTables_pager">
<ul class="pagination">
{% if page.has_previous %}
<li class="page-item">
<a class="page-link" data-page="1" href="?page={{ page.previous_page_number }}">
<i class="fa fa-angle-double-left"></i>
</a>
</li>
{% if page.previous_page_number > 1 %}
<li class="page-item">
<a class="page-link " data-page="{{page.previous_page_number}}" href="?page={{ page.previous_page_number }}">
<i class="fa fa-angle-left"></i>
</a>
</li>
{% endif %}
{% endif %}
{% if page.previous_page_number > 2 %}
<li class="page-item">
<a class="page-link " data-page="{{page.number|add:'-2'}}" href="?{{page.number|add:'-2'}}"> {{ page.number|add:"-2" }} </a>
</li>
<li class="page-item">
<a class="page-link " data-page="{{page.number|add:'-1'}}" href="?page={{page.number|add:'-1'}}"> {{ page.number|add:"-1" }} </a>
</li>
{% endif %}
<li class="page-item active"><span class="page-link ">{{ page.number }}</span></li>
{% if page.paginator.num_pages > page.number|add:"2" %}
<li class="page-item">
<a class="page-link " data-page="{{page.number|add:'1'}}" href="?page={{page.number|add:'1'}}"> {{ page.number|add:"1" }} </a>
</li>
<li class="page-item">
<a class="page-link " data-page="{{page.number|add:'2'}}" href="?page={{page.number|add:'2'}}"> {{ page.number|add:"2" }} </a>
</li>
{% endif %}
{% if page.has_next %}
<li class="page-item">
<a class="page-link " data-page="{{page.next_page_number}}" href="?page={{ page.next_page_number }}">
<i class="fa fa-angle-right"></i>
</a>
</li>
<li class="page-item">
<a class="page-link " data-page="{{page.paginator.num_pages}}" href="?page={{page.paginator.num_pages}}">
<i class="fa fa-angle-double-right"></i>
</a>
</li>
{% endif %}
</ul>
</div>
{% endif %}
</div>
</nav>
My design just like this. If you change design for your needs.
Here click << to go first page , >> to go last page , < to go previous page and > to go next page.
Don't properties overflow-y: scroll; overflow-x: visible; to one element. Help solve the problem. If the left menu is collapsed, when you hover over the li with a child element with class submenu, the submenu doesn't appear because of overflow-y scroll. How to get around the problem?
.fixed-leftmenu .col-left-nano {
position : relative;
width : 100%;
height : 100%;
overflow : visible;
}
.fixed-leftmenu .col-left-nano > .col-left-nano-content {
position : absolute;
overflow-y : scroll;
overflow-x : visible;
top : 0;
right : 0;
bottom : 0;
left : 0;
}
.fixed-leftmenu #nav-col {
height: 100%;
}
<section id="col-left" class="col-left-nano">
<div id="col-left-inner" class="col-left-nano-content" style="padding-right: 12px">
<div class="collapse navbar-collapse navbar-ex1-collapse" id="sidebar-nav">
<ul class="nav nav-pills nav-stacked">
<li>
<a href="{% url 'lk' %}" class="
{% if request.path == '/lk/' %} active {% endif %}">
<i class="fa fa-home"></i>
<span>blabla</span>
</a>
</li>
<li>
{% url 'calendar' as calendar_url %}
<a href="{{ calendar_url }}" class="
{% if calendar_url == request.path %} active {% endif %}">
<i class="fa fa-calendar"></i>
<span>blabla</span>
</a>
</li>
<li>
{% url 'lesson_list' as lesson_list_url %}
<a href="{{ lesson_list_url }}" class="{% if lesson_list_url == request.path %} active {% endif %}">
<i class="fa fa-mortar-board "></i>
<span>blabla</span>
</a>
</li>
{% if user.is_admin %}
<li class="active open">
<a href="{{ post_office_attachment_list }}" class="dropdown-toggle {% if post_office_attachment_list == request.path %} active {% endif %}">
<i class="fa fa-send-o"></i>
<span>blabla</span>
<i class="fa fa-chevron-circle-right drop-icon"></i>
</a>
<ul class="submenu">
<li>
<a href="{{ post_office_attachment_list }}" class="{% if post_office_attachment_list == request.path %} active {% endif %}">
<i class="fa fa-send-o"></i>
<span>blabla</span>
</a>
</li>
<li>
<a href="{{ post_office_email_list }}" class="{% if post_office_email_list == request.path %} active {% endif %}">
<i class="fa glyphicon-envelope"></i>
<span>blabla</span>
</a>
</li>
<li>
<a href="{{ post_office_logs_list }}" class="{% if post_office_logs_list == request.path %} active {% endif %}">
<i class="fa fa-cogs"></i>
<span>blabla</span>
</a>
</li>
</ul>
</li>
<li>
{% url 'user_answer_list' as user_answer_list %}
<a href="{{ user_answer_list }}" class="{% if user_answer_list == request.path %} active {% endif %}">
<i class="fa glyphicon-pencil"></i>
<span>blabla</span>
</a>
</li>
<li>
{% url 'docs_list' as docs_list %}
<a href="{{ docs_list }}" class="{% if docs_list == request.path %} active {% endif %}">
<i class="fa fa-briefcase"></i>
<span>blabla</span>
</a>
</li>
<li>
{% url 'news_list' as news_list %}
<a href="{{ news_list }}" class="{% if news_list == request.path %} active {% endif %}">
<i class="fa fa-list"></i>
<span>news</span>
</a>
</li>
<li class="active open">
<a href="{{ callback_list }}" class="dropdown-toggle {% if callback_list == request.path %} active {% endif %}">
<i class="fa fa-pencil-square-o"></i>
<span>blabla</span>
<i class="fa fa-chevron-circle-right drop-icon"></i>
</a>
<ul class="submenu">
<li>
<a href="{{ proposal_list }}" class="{% if proposal_list == request.path %} active {% endif %}">
<i class="fa fa-pencil-square-o"></i>
<span>blabla</span>
</a>
</li>
<li>
<a href="{{ callback_list }}" class="{% if callback_list == request.path %} active {% endif %}">
<i class="fa fa-phone"></i>
<span>blabla</span>
</a>
</li>
</ul>
</li>
<li>
{% url 'feedback_list' as feedback_list %}
<a href="{{ feedback_list }}" class="{% if feedback_list == request.path %} active {% endif %}">
<i class="fa fa-comments"></i>
<span>blabla</span>
</a>
</li>
<li class="active open">
<a href="{{ students_list }}" class="dropdown-toggle {% if students_list == request.path %} active {% endif %}">
<i class="fa fa-users"></i>
<span>blabla</span>
<i class="fa fa-chevron-circle-right drop-icon"></i>
</a>
<ul class="submenu">
<li>
<a href="{{ students_list }}" class="{% if students_list == request.path %} active {% endif %}">
<i class="fa fa-users"></i>
<span>blabla</span>
</a>
</li>
<li>
<a href="{{ teacher_list }}" class="{% if teacher_list == request.path %} active {% endif %}">
<i class="fa fa-male"></i>
<span>blabla</span>
</a>
</li>
</ul>
</li>
<li class="{% if direction_url == request.path %}active open{% endif %}
{% if course_list == request.path %}active open{% endif %}">
{% url 'direction_list' as direction_url %}
<a href="{{ direction_url }}" class="dropdown-toggle {% if direction_url == request.path %} active {% endif %}">
<i class="fa fa-university"></i>
<span>blabla</span>
<i class="fa fa-chevron-circle-right drop-icon"></i>
</a>
<ul class="submenu">
<li>
<a href="{{ direction_url }}" class="{% if direction_url == request.path %} active {% endif %}">
<i class="fa fa-university"></i>
<span>blabla</span>
</a>
</li>
<li>
<a href="{{ course_list }}" class="{% if course_list == request.path %} active {% endif %}">
<i class="fa fa-mortar-board"></i>
<span>blabla</span>
</a>
</li>
</ul>
</li>
{% endif %}
<li>
{% url 'certify' as certify_url %}
<a href="{{ certify_url }}">
<i class="fa fa-file-text-o"></i>
<span>blabla</span>
</a>
</li>
</ul>
</div>
</div>
</section>
Property overflow: scroll overlaps the overflow: visible. Therefore, the problem to solve in this way it is impossible.