Building a dropdown filter - html

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>

Related

Liquid not rendering on seperate pages

I've recently been having this problem where includes on separate pages that are not loading correctly.
This is my downloads.html:
---
layout: default
---
{% if site.downloads %}
<div class="my-6">{% include downloads.html %}</div>
{% else %}
<h2>Downloads</h2>
<p>There are no downloads at the time. Come back later!</p>
{% endif %}
But what all that shows are:
Here is my _layouts/default.html:
{% include header.html %}
{% if site.layout == 'stacked' %}
<div class="container-lg py-6 p-responsive text-center">
{% include masthead.html metadata=false %}
<div class="container-md f4 text-left border rounded-2 bg-white p-3 p-sm-5 mt-6">
<p class="f5">{% octicon chevron-left height:16 class:"mr-2 v-align-middle" fill:#0366d6 aria-label:Home %}Home</p>
<h1 class="f00-light lh-condensed mb-5">{{ page.title }}</h1>
{{ content }}
</div>
</div>
{% else %}
<div class="d-md-flex min-height-full {% unless site.style == 'dark' %}border-md-bottom{% endunless %}">
<div class="flex-self-stretch {% if site.style == 'dark' %}bg-gray-dark{% else %}border-md-right border-gray-light bg-white{% endif %} col-md-5 col-lg-4 col-xl-3 px-4 px-md-6 px-lg-7 py-6">
{% include masthead.html metadata=true %}
</div>
<div class="col-md-7 col-lg-8 col-xl-9 px-4 py-6 px-lg-7 border-top border-md-top-0 bg-gray-light" {% if site.style == 'dark' %}style="background-color: #2f363d !important"{% endif %}>
<div class="mx-auto" style="max-width: 900px;">
<div class="f4 {% if site.style == 'dark' %}text-white{% endif %} mb-6">
<div class="f4 {% if site.style == 'dark' %}text-white{% endif %}">
<p class="f5">{% octicon chevron-left height:16 class:"mr-2 v-align-middle" fill:{{ icon_color }} aria-label:Home %}Home</p>
<h1 class="f00-light lh-condensed mb-5">{{ page.title }}</h1>
{{ content }}
</div>
</div>
</div>
</div>
</div>
{% endif %}
{% include footer.html %}
Here is my _includes/downloads.html:
<h2 {% if site.style == 'dark' %}class="text-white"{% endif %}>Downloads</h2>
<p class="f4 mb-4 {% if site.style == 'dark' %}text-white{% else %}text-gray{% endif %}">Most of my downloads/others on GitHub.</p>
<div class="d-flex flex-wrap gutter-condensed mb-4">
{% for download in site.downloads %}
<div class="col-6 col-md-12 col-lg-6 col-xl-4 mb-3">
{% include download-card.html %}
</div>
{% endfor %}
</div>
Here is my _includes/download-card.html:
{% if download.download_url %}
<a href="{{ download.download_url }}" class="github-component position-relative hover-grow height-full no-underline d-flex flex-column flex-justify-center text-center border border-gray-light rounded-1 bg-white p-5">
{% if download.image_url %}
<img src="{{ download.image_url }}" width="64" height="64" class="mx-auto rounded-1 mb-3" alt="{{ download.name }}">
{% else %}
<div
class="bg-blue-light f4 text-gray-light text-bold rounded-1 flex-shrink-0 text-center mx-auto mb-3"
style="width:64px; height:64px; line-height:64px;"
>
#
</div>
{% endif %}
<p class="f3 lh-condensed text-center link-gray-dark mb-0 mt-1">{{ download.name }}</p>
{% if download.description %}
<p class="f5 text-gray text-center mb-0 mt-1">{{ download.description }}</p>
{% endif %}
</a>
{% endif %}
And here is my _config.yml:
layout: sidebar
style: dark
plugins:
- jekyll-octicons
- jekyll-github-metadata
- jemoji
permalink: /:year/:month/:day/:title/
defaults:
- scope:
path: ""
type: "posts"
values:
layout: "post"
downloads:
- name: Test
description: This is just a test item
image_url: https://raw.githubusercontent.com/github/explore/6c6508f34230f0ac0d49e847a326429eefbfc030/topics/css/css.png
download_url: https://example.com
It renders perfectly fine on my home layout:
{% include header.html %}
{% if site.layout == 'stacked' %}
<div class="container-lg py-6 p-responsive text-center">
{% include masthead.html metadata=true %}
<div {% if site.style == 'dark' %}class="text-white"{% endif %}>
{{ content }}
</div>
{% if site.topics %}
<div class="my-6">
{% include interests.html %}
</div>
{% endif %}
{% unless posts_total == 0 %}
<div class="my-6">
{% include thoughts.html %}
</div>
{% endunless %}
</div>
{% else %}
<div class="d-md-flex min-height-full {% unless site.style == 'dark' %}border-md-bottom{% endunless %}">
<div class="flex-self-stretch {% if site.style == 'dark' %}bg-gray-dark{% else %}border-md-right border-gray-light bg-white{% endif %} col-md-5 col-lg-4 col-xl-3 px-4 px-md-6 px-lg-7 py-6">
{% include masthead.html metadata=true %}
</div>
<div class="col-md-7 col-lg-8 col-xl-9 px-4 py-6 px-lg-7 border-top border-md-top-0 bg-gray-light" {% if site.style == 'dark' %}style="background-color: #2f363d !important"{% endif %}>
<div class="mx-auto" style="max-width: 900px;">
{% unless content == "" %}
<div class="f4 {% if site.style == 'dark' %}text-white{% endif %} mb-6">
{{ content }}
</div>
{% endunless %}
{% if site.topics %}
{% include interests.html %}
{% endif %}
{% unless posts_total == 0 %}
{% include thoughts.html %}
{% endunless %}
</div>
</div>
</div>
{% endif %}
{% include footer.html %}
Thanks if you can help. I really don't know why this is happening.

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>

How to display 24 items in a carousel - 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>

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.

Split HTML in Twig conditional

I would like to do this inside a for loop
{% if count % 2 == 0 %}
<div class="col-md-6"><!--start block-->
<div class="item-small gutter-bottom">
<img src="{{ item.image_url }}"/>
<div class="item-title">{{ item.name }}</div>
</div>
{% else %}
<div class="item-small gutter-bottom">
<img src="{{ item.image_url }}"/>
<div class="course-title">{{ item.name }}</div>
</div>
</div><!--end block-->
{% endif %}
where I put an additional div wrapping every two items. However, when rendered in HTML, the closing tags went all wrong and the output is not pleasant.
You should use twig's batch method instead.
{% for row in items|batch(2) %}
<div class="col-md-6"><!--start block-->
{% for item in row %}
<div class="item-small gutter-bottom">
<img src="{{ item.image_url }}"/>
<div class="item-title">{{ item.name }}</div>
</div>
{% endfor %}
</div><!--end block-->
{% endfor %}
I'd do this in this way (I put an own example for the loop):
{% for i in 0..9 %}
{% if loop.index0 % 2 == 0 %}
<div class="col-md-6"><!--start block-->
<div class="item-small gutter-bottom">
<img src="{{ item.image_url }}"/>
<div class="item-title">{{ item.name }}</div>
</div>
{% else %}
<div class="item-small gutter-bottom">
<img src="{{ item.image_url }}"/>
<div class="course-title">{{ item.name }}</div>
</div>
</div><!--end block-->
{% endif %}
{% endfor %}
You need to take care about the indexes of the loop, because if the 'if' code is not rendered first, your rendered html wouldn't be good, and the same occurs if in the last iteration the 'else' code is not rendered.