How to arrange content into grid view dynamically? - html

I want to arrange the following Figure1 content into horizon grid view, here content coming into vertical so, how to arrange into horizontal grid view, like Figure2
Figure1:
Figure2:
Here I only required the css class in div, Please tell the css class to arrange the grid into horizontal form.
Jinja2 Templates
_data_grid.html
This template, takes rows(number of data, like in the following Figure2 we have 5 data), and columns(Image Name, Type, Status, public, protected, Formate, size, Action), All these info comes from the database and django framework.
{% load i18n %}
{% with table.needs_form_wrapper as needs_form_wrapper %}
<div class="table_wrapper">
{% if needs_form_wrapper %}<form action="{{ table.get_full_url }}" method="POST">{% csrf_token %}{% endif %}
{% with columns=table.get_columns rows=table.get_rows %}
{% block grid %}
<grid id="{{table.slugify_name}}">
<div>
{% block grid_caption %}
<h3 class='table_title'>{{ table }}</h3>
{{ table.render_table_actions }}
{% endblock grid_caption %}
</div>
</br>
</br>
</br>
</br>
{% block grid_body %}
<div>
{% for row in rows %}
{{ row.render }}
{% empty %}
{{ table.get_empty_message }}
{% endfor %}
</div>
{% endblock grid_body %}
</grid>
{% endblock grid %}
{% endwith %}
{% if needs_form_wrapper %}</form>{% endif %}
</div>
{% endwith %}
_data_grid_cell.html
This template is used to fill the content,
{% if cell.inline_edit_mod and cell.update_allowed %}
{% else %}
{% if cell.inline_edit_available and cell.update_allowed %}
{% else %}
<ul>{{ cell.value }}</ul>
{% endif %}
{% endif %}

If you want to code the css your self flexbox will be what you are looking for. But I will be easier and probably cleaner to use css frameworks like Bootstrap, your code should look somthing like this, then you can add django template tags:
<div class="container">
<div class="row">
<div class="col-sm-4 col-md-4"><!--block 1--></div>
<div class="col-sm-4 col-md-4"><!--block 2--></div>
<div class="col-sm-4 col-md-4"><!--block 3--></div>
<div class="col-sm-4 col-md-4"><!--block 4--></div>
</div>
</div>
Check (Bootstrap Grid) for more details and explanation for the css classes.

Related

HTML search function using a wildcard - shopify

I am a super beginner with HTML, however, I am trying to resolve an issue with my website. I am trying to concatenate a wildcard(*) to the end of whatever a consumer tries to search so that it picks up similarly tagged items, however, I cannot figure out where to add said code... Our current search query works well when pulling up items based on partial keywords, but when hitting the 'enter' button it will say it could not find any products.
Additional notes: This is a Shopify website with a theme from halothemes so most of this is coded by them.
{% assign grid_results = true %}
<div class="search-page collection-template" data-search-page>
<div class="container">
{% if search.performed %}
{% comment %}
Avoid accessing search.results before the opening paginate tag.
If you do, the pagination of results will be broken.
{% endcomment %}
{% paginate search.results by 15 %}
{% comment %}
We don't have any results to show. Feel free to show off featured products
or suggested searches here.
{% endcomment %}
{% if search.results_count == 0 %}
<header class="page-header">
<h2>
{% render 'multilang' with settings.search_1 %}
<strong> "{{ search.terms }}" </strong>
{% render 'multilang' with settings.search_2 %}
</h2>
</header>
{% else %}
<header class="page-header">
<h2>
{% render 'multilang' with settings.search_3 %}
<strong> "{{ search.terms }}" </strong>
{% render 'multilang' with settings.search_4 %}
</h2>
</header>
{% comment %}
Each result template, based on the grid_layout variable above
{% endcomment %}
<div class="block-row col-main">
{% if grid_results == false %}
<div class="product-collection products-list product-search row">
{% for product in search.results %}
<div class="grid-item col-12{% if settings.product_image_border%} grid-item-border{% endif %}">
{% render 'search-result' with product as product %}
</div>
{% endfor %}
</div>
{% else %}
<div class="products-grid product-search row product-collection">
{% for product in search.results %}
<div class="grid-item col-6 col-md-4{% unless settings.layout_style == 'layout_style_1170' %} col5 col-lg-3{% endunless %}{% if settings.product_image_border%} grid-item-border{% endif %}">
{% if settings.style_product_grid == 'style_product_grid_2' %}
{% render 'product-grid-item-style-2' with product as product %}
{% else %}
{% render 'product-grid-item' with product as product %}
{% endif %}
</div>
{% endfor %}
</div>
{% endif %}
</div>
{% endif %}
{% if paginate.pages > 1 %}
<div class="padding">
{% render 'pagination-page' paginate: paginate %}
</div>
{% endif %}
{% endpaginate %}
{% else %}
{% comment %}
If search.performed is false, someone either accessed the page without
the q parameter, or it was blank.
Be sure to show a search form here, along with anything else you want to showcase.
{% endcomment %}
<header class="page-header">
<h2 style="text-align:center" {% if settings.enable_multilang %}data-translate="general.search.title"{%endif%}>{{ 'general.search.title' | t }}</h2>
<div class="header-search__form">
<form action="/search" method="get" class="search-bar" role="search">
<input type="hidden" name="type" value="product">
<input type="search" name="q"
{% if settings.enable_multilang %} data-translate="general.search.placeholder" translate-item="placeholder"{% endif %}
placeholder="{{ 'general.search.placeholder' | t }}"
class="input-group-field" aria-label="Search Site" autocomplete="off">
<button type="submit" class="btn icon-search">
{% render 'icon-search' %}
</button>
</form>
</div>
</header>
{% endif %}
Please let me know if you guys need any additional information! Thank you!
You can use a simple script to add a wildcard to the search query on submitting the form e.g:
var searchForm = document.querySelector(".search-bar");
searchForm.addEventListener("submit", function(e) {
var searchInput = searchForm.querySelector("[name=q]");
var q = searchInput.value;
if (!q.match(/\*$/)) {
e.preventDefault();
searchInput.value = q + "*";
searchForm.submit();
}
});

Can't display two items inline because one is within a 'for' loop and the other within an 'if' statement

I have to icons on a product page (Shopify's theme). I have the following code that displays the icons correctly, except I don't know how to display them inline. I tried wrapping everything in a div or a span with no luck. Here's the code:
<div class="barra-de-info">
{% for tag in product.tags %}
{% if tag contains '_hecho _en _mexico' %}
<div class"icono-hecho-en-mex" style="width: 80px;">{% include 'icon-hecho-en-mexico' %}</div>
{% endif %}
{% endfor %}
{% if product.price >= 60000 %}
<div class"icono-hecho-en-mex">{% include 'icon-free-shipping5' %}</div>
{% endif %}
</div>

How to create 2 columns using the batch filter in twig

Im trying to put Pictures into a gallery using the batch filter with twig. I want there to be 2 columns next to eachother, but the code seems not to create the second column. Everything goes into a single column.
{% extends "_bildlayout" %}
{% block content %}
{% for entry in craft.entries.section('bilder').limit(16)|batch(8) %}
<div class="column">
{% for value in entry %}
{% set bild = value.bild.one() %}
<img src="{{ bild.url }}" alt="{{ value.title }}">
{% endfor %}
</div>
{% endfor %}
{% endblock %}

blog tag produces error right after if statement

I am trying to render three columns for per row in my html file by using Django2.1 and Bootstrap4.
The piece of HTML code looks like following:
<main class="container" role="main">
{% for treasure in treasures %}
{% block row %}
<div class="col-sm-4 py-2">
<div class="card card-body h-100">
<h4 class="card-title">{{ treasure.name }} </h4>
<img class="card-img-bottom mw-100 mh-100" src="{{ treasure.img_url }}" alt="A Kind of Treasure">
</div>
</div>
{% if forloop.counter|divisibleby:3 %}
{% endblock %} {% block row %}
{% endif %}
{% endblock %}
{% endfor %}
</main>
The error I get is:
Invalid block tag on line 44: 'endblock', expected 'elif', 'else' or 'endif'. Did you forget to register or load this tag?
PS: Line 44 is {% endblock %} {% block row %}, so I get the error right after the if check. If I delete that line, it does not produce any error.
Your first {% endblock %} tag is overlapping with the {% if forloop.counter|divisibleby:3 %} tag.
You are basically doing the following:
{% block row %}
{% if forloop.counter|divisibleby:3 %}
{% endblock %}
{% block row %}
{% endif %}
{% endblock %}
Your if tag and endif tag are in two separate blocks, this is causing the error. You wil have to remove the block tags between the if tags.
Adding to the previous answer, you can rename your blocks, and for clarity, add the name in the endblock tag.
{% for treasure in treasures %}
{% block row %}
...
{% if forloop.counter|divisibleby:3 %}
{% block row2 %}
{% endblock row2 %} # add the name in endblock for clarity
{% endif %}
{% endblock row %} # add the name in endblock for clarity
{% endfor %}

HTML/CSS, adding links to changing images

I am very new to this, so any help would be much appreciated.
I am in the process of learning to code and am using templates as guides, and I am using this slideshow template to create a slideshow. But the issue is that, for example, there are four images on the slideshow, but only one link button, linking to only one url. However, I want to code it so that I can link a different url to each of the four images. Below are the codes...
{% if settings.show_block_lookbook %}
<div id="lookbook-section" class="section-full lookbook-section">
<div class="lookbook-wrapper">
<div class="lookbook-text">
<div class="lookbook-container">
<div class="container">
<div class="lb-text">
{% assign lbText1 = settings.block_lookbook_text_1 %}
{% assign lbText2 = settings.block_lookbook_text_2 %}
{% assign lbText3 = settings.block_lookbook_text_3 %}
{% assign lbText4 = settings.block_lookbook_text_4 %}
{% assign lbLink = settings.block_lookbook_link_1 %}
{% if lbText1 != blank %}<h3>{{ lbText1}}</h3>{% endif %}
<div class="bg-slider-arrows">
<span class="button-prev no-border"></span>
<span class="button-next no-border"></span>
</div>
{% if lbText2 != blank %}<h2>{{ lbText2 }}</h2>{% endif %}
{% if lbText3 != blank %}<p>{{ lbText3 }}</p>{% endif %}
{% if lbText4 != blank %}{{ lbText4 }}{% endif %}
</div>
</div>
</div>
</div>
</div>
<div class="lookbook-bg">
{% for i in (1..4) %}
{% assign newShow = 'block_lookbook_img_' | append: i %}
{% if settings[newShow] %}
{% assign newImage = 'block_lookbook_img_' | append: i %}
<div class="lookbook-item">
<img src = "{{ newImage | append: '.jpg' | asset_url}}" alt="" />
</div>
{% endif %}
{% endfor %}
</div>
</div>
{% endif %}
Simply said, what are the codes to put in if I want to make it so that I can add in a different url for each images. I have tried and tried but to no avail, so if someone can help with code samples, it would be much appreciated...