How to display 24 items in a carousel - Jekyll - jekyll

Im working in a project and currently I have a data file that display 24 clients in a page that im taking for a data file
{% for client in site.data.clients %}
<li>
<a href="{{client.URL}}" target="_blank">
<img src="{% asset_path {{client.image}} %}"
alt="{{ client.alt }}">
</a>
</li>
{% endfor %}
I would like to implement a carousel that display 12 items in one slide (and when clicked the arrow) display the other 12 items.
"Two slides with 12 elements each"
I've tried to implement that in the owl carousel but somehow is inserting me all the items in the first element of the first slide. still trying to find a way to split all the elements in two slides like the picture.
what i have implemented so far:
<div class="testi-service owl-carousel owl-theme ">
{% for client in site.data.clients %}
{% if forloop.index > 24 %}
{% assign slidenum = 2 %}
{% else %}
{% assign slidenum = 1 %}
{% endif %}
<div class="owl-item">
<div class="oc-item slide{{ slidenum }}">
<a href="{{client.URL}}" target="_blank">
<img src="{% asset_path {{client.image}} %}" alt="{{ client.alt }}">
</a>
</div>
</div>
{% endfor %}
</div>
</div>

This can be achieved with the following Liquid:
{% for client in site.data.clients %}
{% if forloop.index > 12 %}
{% assign slidenum = 2 %}
{% else %}
{% assign slidenum = 1 %}
{% endif %}
<li class="slide{{ slidenum }}">
<a href="{{client.URL}}" target="_blank">
<img src="{% asset_path {{client.image}} %}" alt="{{ client.alt }}">
</a>
</li>
{% endfor %}
And this css:
.slide2 {display:none;}
You can control the carousel with the following jQuery:
setInterval(function(){
$("[class^='slide']").toggle();
}, 3000);

Somehow it worked like this. just trying to fix the resizing and responsive problem at the moment
<div class=" col-md-9 clients side padding-content">
<div class="client-carousel">
<div class="container">
<div class="owl-item">
<div class="oc-item">
<ul class="clients-grid grid-6 nobottommargin clearfix">
{% comment %}
`site.data.clients` defined in `_data/clients.yml`
{% endcomment %}
{% for client in site.data.clients %}
{% if forloop.index > 24 %}
{% assign slidenum = 2 %}
{% else %}
{% assign slidenum = 1 %}
{% endif %}
<li class="slide{{ slidenum }}">
<a href="{{client.URL}}" target="_blank">
<img src="{% asset_path {{client.image}} %}" alt="{{ client.alt }}">
</a>
</li>
{% endfor %}
</ul>
</div>
</div>
</div>
<div class="container">
<div class="owl-item">
<div class="oc-item">
<ul class="clients-grid grid-6 nobottommargin clearfix">
{% comment %}
`site.data.clients` defined in `_data/clients.yml`
{% endcomment %}
{% for client in site.data.clients %}
{% if forloop.index > 24 %}
{% assign slidenum = 2 %}
{% else %}
{% assign slidenum = 1 %}
{% endif %}
<li class="slide{{ slidenum }}">
<a href="{{client.URL}}" target="_blank">
<img src="{% asset_path {{client.image}} %}" alt="{{ client.alt }}">
</a>
</li>
{% endfor %}
</ul>
</div>
</div>
</div>
</div>

Related

Django pagination not showing links to other page links

I am following a django book to learn django.I tried implementing pagination on a differnt website,it worked.But it's not working in my fyp.Each page has 3 objects as specified by me but the links to change pages are not appearing.
My views.py:-
from django.shortcuts import render
from .models import song_thumb
from django.core.paginator import Paginator,EmptyPage,PageNotAnInteger
from django.views.generic import ListView
# Create your views here.
class SongListView(ListView):
model=song_thumb
context_object_name='artists'
paginate_by=3
template_name='home.html'
my template:
{% block content %}
<form class="" action="mediaplayer.html" method="get">
<div class="data-content">
{% for artist in artists %}
<div class="container">
<div id="img-1" class="tabcontent">
<div class="blog-content">
<div class="row">
<div class="col-sm">
<div class="card" style="width: 18rem;">
<div class="img">
<img class="img-thumbnail" src="{{ artist.img.url }}" alt="">
</div>
<div class="card-body">
<div class="title">
<p>{% trans 'Artist:' %} {{artist.artist}} </p><br>
<p>{% trans 'Title:' %} {{artist.song_title}}</p><br>
<p>{% trans 'Album:' %} {{artist.album}}</p><br>
<p>{% trans 'Duration' %} {{artist.song_duration}}</p><br>
</div>
<audio controls>
<source src='{{ artist.song.url }}' type="audio/mpeg">
Your browser does not support the audio element.
</audio>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{% endfor %}
</div>
</form>
{% include "pagination.html" with page=page_obj %}
{% endblock %}
my pagination.html:
<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>
The pages have 3 objects each as specified by me.But the links to change page numbers are not showing up.
Change your pagination code like this:
<!-- Pagination -->
{% if is_paginated %}
<ul class="pagination justify-content-center mb-4">
{% if page_obj.has_previous %}
<li class="page-item">
<a class='page-link' href='?page=1'>First</a>
</li>
<li class="page-item">
<a class='page-link' href='?page={{ page_obj.previous_page_number }}'>«</a>
</li>
{% endif %}
{% for num in page_obj.paginator.page_range %}
{% if page_obj.number == num %}
<li class="page-item disabled">
<a class='page-link' href='?page={{ num }}'>{{ num }}</a>
</li>
{% elif num > page_obj.number|add:'-3' and num < page_obj.number|add:'3' %}
<li class="page-item">
<a class='page-link' href='?page={{ num }}'>{{ num }}</a>
</li>
{% endif %}
{% endfor %}
{% if page_obj.has_next %}
<li class="page-item">
<a class='page-link' href='?page={{ page_obj.next_page_number }}'>»</a>
</li>
<li class="page-item">
<a class='page-link' href='?page={{ page_obj.paginator.num_pages }}'>Last</a>
</li>
{% endif %}
</ul>
{% endif %}
No need to create separate page for pagination, you can use your template page also for same. I had same issue and for that i referred many solution and this one worked for me here is the pagination code I had used in my project
{% if is_paginated %}
{% if page_obj.has_previous %}
<a class="btn btn-outline-info mb-4" href="?page=1">First</a>
<a class="btn btn-outline-info mb-4" href="?page={{ page_obj.previous_page_number }}">Previous</a>
{% endif %}
{% for num in page_obj.paginator.page_range %}
{% if page_obj.number == num %}
<a class="btn btn-info mb-4" href="?page={{ num }}">{{ num }}</a>
{% elif num > page_obj.number|add:'-3' and num < page_obj.number|add:'3' %}
<a class="btn btn-outline-info mb-4" href="?page={{ num }}">{{ num }}</a>
{% endif %}
{% endfor %}
{% if page_obj.has_next %}
<a class="btn btn-outline-info mb-4" href="?page={{ page_obj.next_page_number }}">Next</a>
<a class="btn btn-outline-info mb-4" href="?page={{ page_obj.paginator.num_pages }}">Last</a>
{% endif %}
{% endif %}
Here is the best tutorial about pagination i hope this will help you
https://www.youtube.com/watch?v=acOktTcTVEQ

Building a dropdown filter

I was wondering if I can have assistance with building a dropdown filter for classes. I was looking at this example: https://codepen.io/luciopaiva/pen/YXYGYE?editors=101 but the difference is that I am using Twig from Advanced Custom Fields Plugin so I cannot manually input the data into the HTML. Here is the HTML I am using. I am trying to make it like this photo. See image here I don't have styling, but this is the logic I am trying to achieve. Basically I am trying to build a relative filter based on what the visitor clicks and have the correct box show below relative to the course. PLEASE HELP!! Thank you!
HTML:
<div class="course-selections filter-section without-background no-left-right">
<div class="customlayout">
{% set category = bloc.training_course_list_compact %}
<h2 class="center-title">{{ category.headline }}</h2>
<div class="inner-class-selection filter-inner-section">
<div class="filter-courses filter-area">
<div class="filter" id="course-solution">
<div class="upper-filter"><h3>Solutions</h3><i class="fas fa-angle-down"></i></div>
<div class="filter-dropdown">
{% for category in bloc.training_course_list_compact.course_categories %}
{% set titleupper = category.title %}
<h4>{{ titleupper|e('wp_kses_post') }}</h4>
{% endfor %}
</div>
</div>
<div class="filter" id="course-type">
<div class="upper-filter"><h3>Class Format</h3><i class="fas fa-angle-down"></i></div>
<div class="filter-dropdown">
{% for category in bloc.training_course_list_compact.course_categories %}
{% for course in category.get_field('courses') %}
{% for classformats in course.get_field('dates') %}
{% set classformat = classformats.class_format %}
{% if classformat == "Lecture" %}
<div class="class-types type-filter lecture"></div>
{% elseif classformat == "Online" %}
<div class="class-types type-filter online"></div>
{% endif %}
{% endfor %}
{% endfor %}
{% endfor %}
<div class="class-title-type type-filter lecture-type"><h4></h4><span></span>
</div>
<div class="class-title-type type-filter online-type"><h4></h4><span></span>
</div>
</div>
</div>
<div class="filter" id="course-location">
<div class="upper-filter"><h3>Locations</h3><i class="fas fa-angle-down"></i></div>
<div class="filter-dropdown">
{% for category in bloc.training_course_list_compact.course_categories %}
{% for locationcourse in category.get_field('courses') %}
{% for location in locationcourse.get_field('dates') %}
<div class="course-location" data-value="{{ location.location }}"></div>
{% endfor %}
{% endfor %}
{% endfor %}
<div class="class-location type-filter"></div>
</div>
</div>
<div class="filter" id="course-date">
<div class="upper-filter"><h3>Start Date</h3><i class="fas fa-angle-down"></i></div>
<div class="filter-dropdown">
{% for category in bloc.training_course_list_compact.course_categories %}
{% for datecourse in category.get_field('courses') %}
{% for dates in datecourse.get_field('dates') %}
<div class="course-date" data-value="{{ dates.date }}"></div>
{% endfor %}
{% endfor %}
{% endfor %}
<div class="class-date type-filter"></div>
</div>
</div>
</div>
<div class="class-blocks">
{% for category in bloc.training_course_list_compact.course_categories %}
{% set thumbnail = category.thumbnail %}
{% set link = category.link %}
{% set titleupper = category.title %}
{% for course in category.get_field('courses') %}
{% set link = course.link %}
{% set title = course.title %}
<div class="class-block">
<a class="class-block-link" href="{{ link|e('esc_url') }}">
<div class="image">
</div>
<h3>{{ title|e('wp_kses_post') }}</h3>
<h4>{{ titleupper|e('wp_kses_post') }}</h4>
</a>
<a class="course-link" href="{{ link|e('esc_url') }}">Course</a>
</div>
{% endfor %}
{% endfor %}
</div>
</div>
</div>

How to place review section in different position for Mobile and Desktop in Shopify?

I have this product-template.liquid file:
<div itemscope itemtype="http://schema.org/Product" id="ProductSection" data-section-id="{{ section.id }}" data-section-type="product-template" data-image-zoom-type="{{ section.settings.product_image_zoom_type }}" data-related-enabled="{{ section.settings.product_related_enable }}" data-show-extra-tab="{{ section.settings.show_extra_tab }}" data-extra-tab-content="{{ section.settings.extra_tab_content }}" data-enable-history-state="true">
{% case section.settings.add_to_cart_width %}
{% when 'small' %}
{%- assign btn_class = 'btn--wide' -%}
{%- assign productform_class = 'product-form--wide' -%}
{% when 'medium' %}
{%- assign btn_class = 'btn--wide' -%}
{%- assign productform_class = 'product-form--wide' -%}
{% when 'large' %}
{%- assign btn_class = 'btn--full' -%}
{%- assign productform_class = 'product-form--full' -%}
{% endcase %}
{% if section.settings.add_to_cart_width != 'small' %}
<style>
#media screen and (min-width: 769px){
.single-option-selector,
.quantity-selector {
{% if section.settings.add_to_cart_width == 'medium' %}
min-width: 50%;
{% else %}
min-width: 100%;
{% endif %}
}
}
</style>
{% endif %}
<meta itemprop="url" content="{{ shop.url }}{{ product.url }}">
<meta itemprop="image" content="{{ product.featured_image.src | img_url: 'grande' }}">
<div class="section-header section-header--breadcrumb">
{% include 'breadcrumb' %}
</div>
<div class="product-single">
<div class="grid product-single__hero">
<div class="grid__item post-large--one-half">
{% if section.settings.product_thumbnails_position == 'below' or product.images.size < 2 %}
<div class="product-single__photos">
{% assign featured_image = product.selected_or_first_available_variant.featured_image | default: product.featured_image %}
{% for image in product.images %}
{% capture img_id %}ProductImage-{{ image.id }}{% endcapture %}
{% capture img_wrapper_id %}ProductImageWrapper-{{ image.id }}{% endcapture %}
{%- assign img_url = image | img_url: '1x1' | replace: '_1x1.', '_{width}x.' -%}
{% include 'image-style' with image: image, small_style: false, width: 700, height: 1024, wrapper_id: img_wrapper_id, img_id: img_id %}
<div id="{{ img_wrapper_id }}" class="product-single__image-wrapper supports-js{% unless featured_image == image %} hide{% endunless %}{% if section.settings.product_image_zoom_type == 'lightbox' %} zoom-lightbox{% endif %}" data-image-id="{{ image.id }}">
<div style="padding-top:{{ 1 | divided_by: image.aspect_ratio | times: 100}}%;">
<img id="{{ img_id }}"
class="product-single__image lazyload{% unless featured_image == image %} lazypreload{% endunless %}"
{% if featured_image == image %}src="{{ image | img_url: '300x300' }}"{% endif %}
data-src="{{ img_url }}"
data-widths="[180, 370, 540, 740, 900, 1080, 1296, 1512, 1728, 2048]"
data-aspectratio="{{ image.aspect_ratio }}"
data-sizes="auto"
{% if section.settings.product_image_zoom_type == 'zoom-in' %} data-zoom="{{ image | img_url: '1024x1024', scale: 2 }}"{% endif %}
alt="{{ image.alt | escape }}">
</div>
</div>
{% endfor %}
<noscript>
<img src="{{ featured_image | img_url: '1024x1024', scale: 2 }}" alt="{{ featured_image.alt | escape }}">
</noscript>
</div>
{% if product.images.size > 1 %}
<ul class="product-single__thumbnails grid-uniform" id="ProductThumbs">
{% for image in product.images %}
<li class="grid__item wide--one-quarter large--one-third medium-down--one-third">
<a data-image-id="{{ image.id }}" href="{{ image.src | img_url: '1024x1024' }}" class="product-single__thumbnail">
<img src="{{ image.src | img_url: 'grande' }}" alt="{{ image.alt | escape }}">
</a>
</li>
{% endfor %}
</ul>
{% endif %}
{% else %}
<div class="grid">
<div class="grid__item four-fifths product-single__photos" id="ProductPhoto">
{% assign featured_image = product.selected_or_first_available_variant.featured_image | default: product.featured_image %}
{% for image in product.images %}
{% capture img_id %}ProductImage-{{ image.id }}{% endcapture %}
{% capture img_wrapper_id %}ProductImageWrapper-{{ image.id }}{% endcapture %}
{%- assign img_url = image | img_url: '1x1' | replace: '_1x1.', '_{width}x.' -%}
{% include 'image-style' with image: image, small_style: false, width: 700, height: 1024, wrapper_id: img_wrapper_id, img_id: img_id %}
<div id="{{ img_wrapper_id }}" class="product-single__image-wrapper supports-js{% unless featured_image == image %} hide{% endunless %}{% if section.settings.product_image_zoom_type == 'lightbox' %} zoom-lightbox{% endif %}" data-image-id="{{ image.id }}">
<div style="padding-top:{{ 1 | divided_by: image.aspect_ratio | times: 100}}%;">
<img id="{{ img_id }}"
class="product-single__image lazyload{% unless featured_image == image %} lazypreload{% endunless %}"
{% if featured_image == image %}src="{{ image | img_url: '300x300' }}"{% endif %}
data-src="{{ img_url }}"
data-widths="[180, 370, 540, 740, 900, 1080, 1296, 1512, 1728, 2048]"
data-aspectratio="{{ image.aspect_ratio }}"
data-sizes="auto"
{% if section.settings.product_image_zoom_type == 'zoom-in' %} data-zoom="{{ image | img_url: '1024x1024', scale: 2 }}"{% endif %}
alt="{{ image.alt | escape }}">
</div>
</div>
{% else %}
<img src="{{ featured_image | img_url: '1024x1024', scale: 2 }}" alt="{{ featured_image.alt | escape }}">
{% endfor %}
<noscript>
<img src="{{ featured_image | img_url: '1024x1024', scale: 2 }}" alt="{{ featured_image.alt | escape }}">
</noscript>
</div>
<div class="grid__item one-fifth">
<ul class="grid product-single__thumbnails" id="ProductThumbs">
{% for image in product.images %}
<li class="grid__item">
<a data-image-id="{{ image.id }}" href="{{ image.src | img_url: '1024x1024' }}" class="product-single__thumbnail">
<img src="{{ image.src | img_url: 'grande' }}" alt="{{ image.alt | escape }}">
</a>
</li>
{% endfor %}
</ul>
</div>
</div>
{% endif %}
{% if section.settings.product_image_zoom_type == 'lightbox' %}
<ul class="gallery" class="hidden">
{% for image in product.images %}
<li data-image-id="{{ image.id }}" class="gallery__item" data-mfp-src="{{ image | img_url: '1024x1024', scale: 2 }}"></li>
{% endfor %}
</ul>
{% endif %}
</div>
<div class="grid__item post-large--one-half">
{% if section.settings.product_vendor_enable %}
<span class="h3" itemprop="brand">{{ product.vendor }}</span>
{% endif %}
<h1 itemprop="name">{{ product.title }}</h1>
<div itemprop="offers" itemscope itemtype="http://schema.org/Offer">
{% assign variant = product.selected_or_first_available_variant %}
<meta itemprop="priceCurrency" content="{{ shop.currency }}">
<link itemprop="availability" href="http://schema.org/{% if product.available %}InStock{% else %}OutOfStock{% endif %}">
<div class="product-single__prices{% if shop.taxes_included or shop.shipping_policy.body != blank %} product-single__prices--policy-enabled{% endif %}">
<span id="PriceA11y" class="visually-hidden">{{ 'products.product.regular_price' | t }}</span>
<span id="ProductPrice" class="product-single__price" itemprop="price" content="{{ product.price | divided_by: 100.00 }}">
{{ product.price | money }}
</span>
{% if product.compare_at_price > product.price %}
<span id="ComparePriceA11y" class="visually-hidden" aria-hidden="false">{{ 'products.product.sale_price' | t }}</span>
<s id="ComparePrice" class="product-single__sale-price">
{{ product.compare_at_price_max | money }}
</s>
{% else %}
<span id="ComparePriceA11y" class="visually-hidden" aria-hidden="true">{{ 'products.product.sale_price' | t }}</span>
<s id="ComparePrice" class="product-single__sale-price hide">
{{ product.compare_at_price_max | money }}
</s>
{% endif %}
</div>
{%- if shop.taxes_included or shop.shipping_policy.body != blank -%}
<div class="product-single__policies{% if product.has_only_default_variant and section.settings.product_quantity_enable == false %} product__policies--no-dropdowns{% endif %} rte">
{%- if shop.taxes_included -%}
{{ 'products.general.include_taxes' | t }}
{%- endif -%}
{%- if shop.shipping_policy.body != blank -%}
{{ 'products.general.shipping_policy_html' | t: link: shop.shipping_policy.url }}
{%- endif -%}
</div>
{%- endif -%}
{% form 'product', product, class:productform_class %}
<select name="id" id="ProductSelect-{{ section.id }}" class="product-single__variants">
{% for variant in product.variants %}
{% if variant.available %}
<option {% if variant == product.selected_or_first_available_variant %} selected="selected" {% endif %} data-sku="{{ variant.sku }}" value="{{ variant.id }}">{{ variant.title }} - {{ variant.price | money_with_currency }}</option>
{% else %}
<option disabled="disabled">
{{ variant.title }} - {{ 'products.product.sold_out' | t }}
</option>
{% endif %}
{% endfor %}
</select>
<div class="product-single__quantity{% unless section.settings.product_quantity_enable %} is-hidden{% endunless %}">
<label for="Quantity">{{ 'products.product.quantity' | t }}</label>
<input type="number" id="Quantity" name="quantity" value="1" min="1" class="quantity-selector">
</div>
<button type="submit" name="add" id="AddToCart" class="btn {{ btn_class }}{% if section.settings.enable_payment_button %} btn--secondary{% endif %}">
<span id="AddToCartText">{{ 'products.product.add_to_cart' | t }}</span>
</button>
{% if section.settings.enable_payment_button %}
{{ form | payment_button }}
{% endif %}
{% endform %}
{% unless section.settings.show_extra_tab == false or pages[section.settings.extra_tab_content] == empty %}
<div class="tabs">
<ul class="tab-switch__nav">
<li>
{{ 'products.product.description' | t }}
</li>
<li>
{{ pages[section.settings.extra_tab_content].title }}
</li>
</ul>
<div id="description" class="tab-switch__content" data-content="description">
<div class="product-description rte" itemprop="description">
{{ product.description }}
</div>
</div>
<div id="extra" class="tab-switch__content" data-content="extra">
<div class="rte">
{{ pages[section.settings.extra_tab_content].content }}
</div>
</div>
</div>
{% else %}
<div class="product-description rte" itemprop="description">
{{ product.description }}
</div>
{% endunless %}
<div id="shopify-product-reviews" data-id="{{product.id}}">{{ product.metafields.spr.reviews }}</div>
{% if section.settings.social_sharing %}
<hr class="hr--clear hr--small">
<h2 class="h4">{{ 'products.general.share_title' | t }}</h2>
{% include 'social-sharing' %}
{% endif %}
</div>
</div>
</div>
</div>
{% if section.settings.product_related_enable %}
{% include 'related-products' %}
{% endif %}
</div>
{% unless product == empty %}
<script type="application/json" id="ProductJson-{{ section.id }}">
{{ product | json }}
</script>
{% endunless %}
How can i achieve this reviews section location different for mobile and desktop. I want reviews section below big image in desktop and in mobile version i want it below specification section.
I tried adding it below product description section but in mobile version it is now showing under product image which i don't want. I want it to show under product specification in mobile .... so there is a conflict. How can i have separate little tweak for different version ?
How can i do it?
It's simple CSS hack, you just need to use two different div for desktop and mobile. You can hide one div on Mobile(use CSS class: small--hide) and hide other on desktop (use CSS class: medium-up--hide).
Reference code for Debut Theme
<div class="grid__item medium-up--one-half small--hide">
<!-- Content to be shown on Desktop -->
</div>
<div class="mobile-nav-wrapper medium-up--hide">
<!-- Content to be shown on Mobile -->
</div>
add 2 divs one for mobile and one for desktop use visibility likewise if in desktop hide mobile div and in mobile div hide desktop div.
You have to put code inside 2 divs for show widget given by review app you are using on your store.
If any help i am available to help you.
I have created 150+ stores on shopify and still creating more.
{% comment %} Div below is for Desktop Content {% endcomment %}
<div class="grid__item small--hide">
Insert whatever content you want to show on Tablet/Desktop here
</div>
{% comment %} Div below is for Moblie Content {% endcomment %}
<div class="grid__item medium-up--hide">
Insert whatever content you want to show on Mobile here
</div>

how to find first image in a list of images in django

I have a Django template render result and images for search of cars. as follow:
{% for item in result %}
<li class="result-row">
<!-- image box -->
<span>
<a href="#" class="result-image-act" >
{% for image in item.images_cars_set.all %}
{% if image.car_images_exists %}
{% if image.car_images.0 %}
<img class="active" src=" {{image.car_images.url}}">
{% endif %}
{% if not image.car_images.0 %}
<img src=" {{image.car_images.url}}">
{% endif%}
{% endif %}
{% empty %}
<img src="{% static 'path/to/default image' %}" class="active">
{% endfor %}
</a>
<span class="embed-result-price">{{item.price}}</span>
<div class="swipe-wrap">
<div class="swipe-wrap-lef">
<span class="move" >
<div class="swipe-prev">
<p><</p>
</div>
</span>
</div>
<div class="swipe-wrap-rig">
<span class="move" >
<div class="swipe-next">
<p>></p>
</div>
</span>
</div>
</div>
</span>
The code is working fine except that I want to find the first image and put it in different img tag where it will take class="active". This class is used in javascript code to swipe all images to left or right. I tried to use {% if image.car_images.0 %} and {% if image.car_images.first %} to find first image but not success. what I get is all images without class of active. any help or suggestion.
You can use {% if forloop.counter0 == 0 %} do something {% endif %} or
{% if forloop.counter == 1 %} do something {% endif %} to do something for the 1st item when iterating with a {% for %} template tag.
More info: https://docs.djangoproject.com/en/2.1/ref/templates/builtins/#for
Thus your code should be something like
<a href="#" class="result-image-act" >
{% for image in item.images_cars_set.all %}
{% if forloop.counter == 1 %}
<img class="active" src=" {{image.car_images.url}}">
{% else %}
<img src=" {{image.car_images.url}}">
{% endif %}
{% empty %}
<img src="{% static 'path/to/default image' %}" class="active">
{% endfor %}
</a>

Jekyll filter categories and posts by tags

In Jekyll I filter posts by tags displating a list of the posts which have the assigned tag like this:
---
layout: layout
---
<ul>
{% for post in site.posts %}
{% for tag in post.tags %}
{% if tag == page.tag %}
<li itemprop="name" itemprop=name>{{ post.title }}</li>
{% endif %}
{% endfor %}
{% endfor %}
</ul>
Burt what I'd like to do is display the categories which have posts of the tag and the posts listed under each category.
Example use case
Category 1 has post 1, post 2, post 3.
Category 2 has post 4, post 5, post 6.
Category 3 has post 7
Posts 1,2,4 have tag Tag1.
The tag page should display Category 1 + Post 1, post 2. Category 2 + Post 4.
On the homepage I display categories with all posts under each category like this:
{% assign counter=0 %}
<main id="page" role="main">
{% for category in site.categories %}
<div class="col pane ui-layout-{% assign counter=counter | plus:1 %}" id="{{ page.id }}">
<div class="colheader">
<div class="bar"></div>
<p class="lead">Leadin text</p>
<h1>{{ category | first }}</h1>
</div>
<div class="colscroll unlock">
{% for posts in category %}
{% for post in posts %}
<div class="colblock" itemscope itemtype="http://schema.org/BlogPosting">
<div class="excerpt">
<time class="date" datetime="{{ page.date | '%Y-%m-%dT%H:%i:%S-08:00' }}" itemprop="datePublished">
{{ page.date | date: '%B %d, %Y' }}
</time>
<h1>
<a itemprop="url" href="{{ post.url }}" target="_blank" title="{{ post.title }}">
<span itemprop="name" itemprop=name>{{ post.title }}</span>
</a>
</h1>
<p itemprop="description">
{{ post.excerpt }}..
</p>
<p class="link_tags">{{ page.tags }}</p>
</div>
</div>
{% endfor %}
{% endfor %}
</div>
</div>
{% endfor %}
</main>
So on the tag page I try to achieve what I want like this but it is returning all categories and all posts just like the homepage rather than filtering by the tag.
---
layout: layout
---
<ul>
{% for post in site.posts %}
{% for tag in post.tags %}
{% if tag == page.tag %}
{% assign counter=0 %}
<main id="page" role="main">
{% for category in site.categories %}
<div class="col pane ui-layout-{% assign counter=counter | plus:1 %}" id="{{ page.id }}">
<div class="colheader">
<div class="bar"></div>
<p class="lead">Leadin text</p>
<h1>{{ category | first }}</h1>
</div>
<div class="colscroll unlock">
{% for posts in category %}
{% for post in post.tags %}
<div class="colblock" itemscope itemtype="http://schema.org/BlogPosting">
<div class="excerpt">
<time class="date" datetime="{{ page.date | '%Y-%m-%dT%H:%i:%S-08:00' }}" itemprop="datePublished">
{{ page.date | date: '%B %d, %Y' }}
</time>
<h1>
<a itemprop="url" href="{{ post.url }}" target="_blank" title="{{ post.title }}">
<span itemprop="name" itemprop=name>{{ post.title }}</span>
</a>
</h1>
<p itemprop="description">
{{ post.excerpt }}..
</p>
<p class="link_tags">{{ page.tags }}</p>
</div>
</div>
{% endfor %}
{% endfor %}
</div>
</div>
{% endfor %}
</main>
{% endif %}
{% endfor %}
{% endfor %}
</ul>
I alsio tried this but it returns a blank page
---
layout: layout
---
<ul>
{% for post in site.posts %}
{% for tag in post.tags %}
{% if tag == page.tag %}
{% assign counter=0 %}
<main id="page" role="main">
{% for category in tag.categories %}
<div class="col pane ui-layout-{% assign counter=counter | plus:1 %}" id="{{ page.id }}">
<div class="colheader">
<div class="bar"></div>
<p class="lead">Leadin text</p>
<h1>{{ category | first }}</h1>
</div>
<div class="colscroll unlock">
{% for posts in category %}
{% for post in tag.posts %}
<div class="colblock" itemscope itemtype="http://schema.org/BlogPosting">
<div class="excerpt">
<time class="date" datetime="{{ page.date | '%Y-%m-%dT%H:%i:%S-08:00' }}" itemprop="datePublished">
{{ page.date | date: '%B %d, %Y' }}
</time>
<h1>
<a itemprop="url" href="{{ post.url }}" target="_blank" title="{{ post.title }}">
<span itemprop="name" itemprop=name>{{ post.title }}</span>
</a>
</h1>
<p itemprop="description">
{{ post.excerpt }}..
</p>
<p class="link_tags">{{ page.tags }}</p>
</div>
</div>
{% endfor %}
{% endfor %}
</div>
</div>
{% endfor %}
</main>
{% endif %}
{% endfor %}
{% endfor %}
</ul>
The live site template is up on Github. (tags list is the second circular icon from the left at the top of the page)
I think this is what you are looking for:
---
layout: default
---
<main id="page" role="main">
{% for category in site.categories %}
{% assign counter=0 %}
{% for posts in category %}
{% for post in posts %}
{% if post.tags contains page.tag %}
{% assign counter=counter | plus:1 %}
{% endif %}
{% endfor %}
{% endfor %}
{% if counter != 0 %}
<div class="col pane ui-layout-{% assign counter=counter | plus:1 %}" id="{{ page.id }}">
<div class="colheader">
<div class="bar"></div>
<p class="lead">Leadin text</p>
<h1>{{ category | first }}</h1>
</div>
<div class="colscroll unlock">
{% for posts in category %}
{% for post in posts %}
{% if post.tags contains page.tag %}
<div class="colblock" itemscope itemtype="http://schema.org/BlogPosting">
<div class="excerpt">
<time class="date" datetime="{{ page.date | '%Y-%m-%dT%H:%i:%S-08:00' }}" itemprop="datePublished">
{{ page.date | date: '%B %d, %Y' }}
</time>
<h1>
<a itemprop="url" href="{{ post.url }}" target="_blank" title="{{ post.title }}">
<span itemprop="name" itemprop=name>{{ post.title }}</span>
</a>
</h1>
<p itemprop="description">
{{ post.excerpt }}..
</p>
<p class="link_tags">{{ page.tags }}</p>
</div>
</div>
{% endif %}
{% endfor %}
{% endfor %}
</div>
</div>
{% endif %}
{% endfor %}
</main>
I've just modified your homepage code.
Edit: Added conditional code. Print only categories that contains posts with current tag.