I want to include multiple layout file in index file of view and extends all of them from master.volt. But my problem is level-1.volt doesn't render when I run index.volt. Is my workflow ok? What is the problem?
I have on base view file named master.volt that have basic view of my frontend:
<div class="row justify-content-center" id="Level-1">
<div class="col-11">
<div class="row flex-column justify-content-center align-items-center">
{% block bannerOne %}
{% endblock %}
</div>
</div>
</div>
I have one view file named level-1.volt:
{% block bannerOne %}
<div class="col-12 d-flex justify-content-center align-items-center">
<img src="img/pop-1-2.png" class="img-fluid"/>
</div>
{% endblock %}
And this is my index.volt view:
{% extends 'master/master.volt' %}
{% include 'layouts/level-1.volt' %}
Related
I have made a django e-comm website , when I press the add to cart button on my home page I have written a function which should change the status of a product from false to true once it is added in the cart but it does not work
I have given my cart.py and index.html code
Thank you
cart.py
from django import template
register = template.Library()
#register.filter(name='is_in_cart')
def is_in_cart(product,cart):
keys = cart.keys()
for id in keys:
print(id , product.id)
if int(id) == product.id:
return True
return False
index.html
{% extends 'main/base.html'%}
{% block title %}
index
{% endblock %}
{% block content %}
{% load cart %}
<div class="container-fluid">
<div class="row">
<div class="col-lg-3">
<div class="list-group mt-3">
{% for items in category %}
{{items.Category_name}} <!--i first used a small c for category but it did not pick the words from my category.py fle-->
{% endfor %}
</div>
</div>
<div class="col-lg-9">
<div class="row">
{% for items in product %}
<div class="card mx-auto mb-3 mt-3" style="width: 18rem;">
<img class="card-img-top" src="{{items.product_image.url}}" alt="Card image cap">
<div class="card-body">
<h5 class="card-title">{{items.product_name}}</h5>
<p class="card-text"><b>{{items.product_price}}</b></p>
<p class="card-text"><b>{{items.product_detail}}</b></p>
{{product | is_in_cart:request.session.cart }}
<form action="/" mthod="POST">
{% csrf_token %}
<input hidden type="text" name='product' value='{{items.id}}'>
<input href="#" type="submit" class="float-right btn btn-light border btn-sm" value="Add to Cart">
</form>
</div>
</div>
{% endfor %}
</div>
</div>
</div>
</div>
{% endblock %}
can anyone please help me with this formula? It doesn't give me what I need. The first two posts to the active section, all the others to the inactive one.
{% set memberLength = members|length / 2 %}
{% for i in 1..memberLength %}
{% set sliceStart = i * 2 - 2 %}
{% set sliceLength = 2 %}
{% if i < 2 %}
<div class="carousel-item active">
<div class="row m-0">
{% for key, member in members|slice(sliceStart,sliceLength) %}
<div class="col-lg-6 py-4 ps-lg-3 pe-lg-5 d-lg-block d-none">
<div class="pb-4 mb-2 text-white">
<p class="fw-7 mb-0">{{ member.name }}</p>
<p>{{ member.podjmeno }}</p>
</div>
<div class="text-primary PF fz-19">
<h2 class="fw-4 mb-3">{{ member.nadpisvelky }}</h2>
<p><em>{{ member.description }}</em></p>
</div>
</div>
{% endfor %}
</div>
</div>
{% else %}
<div class="carousel-item">
<div class="row m-0">
{% for key, member in members|slice(sliceStart,sliceLength) %}
<div class="col-lg-6 py-4 ps-lg-3 pe-lg-5 d-lg-block d-none">
<div class="pb-4 mb-2 text-white">
<p class="fw-7 mb-0">{{ member.name }}</p>
<p>{{ member.podjmeno }}</p>
</div>
<div class="text-primary PF fz-19">
<h2 class="fw-4 mb-3">{{ member.nadpisvelky }}</h2>
<p><em>{{ member.description }}</em></p>
</div>
</div>
{% endfor %}
</div>
</div>
{% endif %}
{% endfor %}
If you want to create a repeating HTML structure you are best off with using the filter batch
To set the class active on the first item you can use the attribute first of the loop variable
{% for items in members|batch(2) %}
<div class="carousel-item{{ loop.first ? ' active' }}">
{% for item in items %}
<div class="col-lg-6 py-4 ps-lg-3 pe-lg-5 d-lg-block d-none">
<div class="pb-4 mb-2 text-white">
<p class="fw-7 mb-0">{{ item.name }}</p>
<p>{{ item.podjmeno }}</p>
</div>
<div class="text-primary PF fz-19">
<h2 class="fw-4 mb-3">{{ item.nadpisvelky }}</h2>
<p><em>{{ item.description }}</em></p>
</div>
</div>
{% endfor %}
</div>
{% endfor %}
demo
I was creating a simple blog page using Django. When I added cards for the articles it came like this
There is no space between the cards.
{% extends 'base.html' %}
{% block content %}
<div class="card mt-3" style="width: 100%;">
{% for post in posts %}
<div class="card-header">
<cite title="Source Title">{{ post.author }}</cite>
<small class="text-muted float-right">{{ post.date_posted | date:"F d, Y" }}</small>
</div>
<div class="card-body">
<div class="card-title">{{ post.title }}</div>
<p class="card-text">{{ post.content }}</p>
</div>
{% endfor %}
</div>
{% endblock content %}
How do I add space between these cards?
your for loop is not in correct place change code from
{% extends 'base.html' %}
{% block content %}
<div class="card mt-3" style="width: 100%;">
{% for post in posts %}
<div class="card-header">
<cite title="Source Title">{{ post.author }}</cite>
<small class="text-muted float-right">{{ post.date_posted | date:"F d, Y" }}</small>
</div>
<div class="card-body">
<div class="card-title">{{ post.title }}</div>
<p class="card-text">{{ post.content }}</p>
</div>
{% endfor %}
</div>
{% endblock content %}
to bellow code
{% extends 'base.html' %}
{% block content %}
{% for post in posts %}
<div class="card mt-3" style="width: 100%;">
<div class="card-header">
<cite title="Source Title">{{ post.author }}</cite>
<small class="text-muted float-right">{{ post.date_posted | date:"F d, Y" }}</small>
</div>
<div class="card-body">
<div class="card-title">{{ post.title }}</div>
<p class="card-text">{{ post.content }}</p>
</div>
</div>
{% endfor %}
{% endblock content %}
Firstly, you need to do the loop for every card, instead of doing it for the inner divs 'card-header' and 'card-body'. Secondly, to answer you question, you should use a spacing by either a margin or a padding.
I would suggest to make the cards a standard width and use a 'margin right 3':
{% for post in posts %}
<div class="card mt-3 mr-3" style="width: 250px">
<div class="card-header">
...
</div>
<div class="card-body">
...
</div>
</div>
{% endfor %}
Besides this solution, I suggest you read the Bootstaps Grid Layout documentation, so you can place the cards nicely within your content block.
I created a custom theme in drupal 8.6. Everything works fine but for some reason if I put a content in my sidebar region it goes to the bottom of my page after my main content. Any suggestions on how to fix this would be highly appreciated. Thanks
Here is my page.html.twig
<div class="layout-container">
<header role="banner">
{{ page.header }}
</header>
<main role="main">
<a id="main-content" tabindex="-1"></a>{# link is in html.html.twig #}
<div class="layout-content">
{{ page.content }}
</div>{# /.layout-content #}
{% if page.sidebar %}
<aside class="layout-sidebar-first" role="complementary">
{{ page.sidebar }}
</aside>
{% endif %}
</main>
{% if page.footer %}
<footer role="contentinfo">
{{ page.footer }}
</footer>
{% endif %}
</div>{# /.layout-container #}
st_saviours.info.yml file
name: St Saviours
description: Drupal 8 theme
type: theme
core: 8.x
libraries:
- st_saviours/global-css
- st_saviours/global-js
stylesheets-remove:
- core/themes/stable/css/views/views.module.css
- core/themes/stable/css/system/components/align.module.css
regions:
header : 'Header'
content: 'Main Content'
footer: 'Footer'
sidebar : 'Sidebar'
I used bootstrap grid layout to arrange the main content and the sidebar in my page.html.twig file.
<main role="main">
<a id="main-content" tabindex="-1"></a>{# link is in html.html.twig #}
<div class="col-md-12">
<div class="row">
{% if (page.first_sidebar and page.second_sidebar) %}
<div class="col-md-4">
<aside class="layout-sidebar-first" role="complementary">
{{ page.first_sidebar }}
</aside>
</div>
<div class="col-md-5">
<div class="layout-content">
{{ page.content }}
</div>{# /.layout-content #}
</div>
<div class="col-md-3">
<aside class="layout-sidebar-second" role="complementary">
{{ page.second_sidebar }}
</aside>
</div>
{% else %}
<div class="col-md-12">
<div class="row">
<div class="layout-content">
{{ page.content }}
</div>{# /.layout-content #}
</div>
</div>
{% endif %}
</div>
</div>
</main>
Thanks for the help!
So, I'm trying to create a simple layout with a Bootstrap nav-bar and a block of content on the body, and that works fine. But, when I extend that to a child, no matter what changes I make on the child, nothing shows up!
I'll post the two templates I'm using right now.
layout.html
<!doctype html>
{% extends "bootstrap/base.html" %}
<html>
<head>
<title>{% block title %}{% endblock %} </title>
</head>
<body>
{% block navbar %}
<nav class="navbar navbar-inverse navbar navbar-fixed-stop" role="navigation" style="border-radius:0px;">
<div class="container-fluid">
<div class="navbar-header"><a class="navbar-brand" href="#">BGP Monitor</a></div>
<ul class = "nav navbar-nav">
{% if g.user.is_authenticated %}
<li>Admin Panel</li>
{% endif %}
</ul>
<ul class="nav navbar-nav navbar-right">
{% if g.user.is_authenticated %}
<li><a href ="{{ url_for('logout') }}">Logout</li>
{% else %}
<li><a href ="{{ url_for('login') }}">Login</li>
{% endif %}
</ul>
</div>
</div>
</nav>
{% endblock %}
<div class="container-fluid" id="form">
{% block container %}{% endblock %}
</div>
</body>
</html>
And the child:
{% extends "layout.html" %}
<html>
<head></head>
<body>
<h3>aaa</h3>
{% block container %}
<div class="collapse navbar-collapse" id="container">
{{ super() }}
<form action="{{ url_for('login')}}" class="navbar-form navbar-right" method="POST">
{{ form.hidden_tag() }}
<div class="form-group">
{{ form.email(class="form-control", placeholder="Username") }}
</div>
<div class="form-group">
{{ form.password(class="form-control", placeholder="Password") }}
</div>
<div class="form-group">
<button class="btn btn-default" type="submit">Sign In</button>
</div>
</form>
</div>
</div>
{% endblock %}
</body>
The nav-bar shows, but the form doesn't show up, at all. It's as if the child does not exist.
Any ideas?
Thank you
P.S:
So, I changed to this:
layout.html
<!doctype html>
<html>
<head>
<title>{% block title %}{% endblock %}</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>
<nav class="navbar navbar-inverse navbar navbar-fixed-stop" role="navigation" style="border-radius:0px;">
<div class="container-fluid">
<div class="navbar-header"><a class="navbar-brand" href="#">BGP Monitor</a></div>
<ul class = "nav navbar-nav">
{% if g.user.is_authenticated %}
<li>Admin Panel</li>
{% endif %}
</ul>
<ul class="nav navbar-nav navbar-right">
{% if g.user.is_authenticated %}
<li><a href ="{{ url_for('logout') }}">Logout</li>
{% else %}
<li><a href ="{{ url_for('login') }}">Login</li>
{% endif %}
</ul>
</div>
</div>
</nav>
<div class="container-fluid" id="container">
{% block container %}{% endblock %}
</div>
</body>
</html>
And this child:
{% extends "layout.html" %}
{% block container %}
<form action="{{ url_for('login')}}" class="navbar-form navbar-right" method="POST">
{{ form.hidden_tag() }}
<div class="form-group">
{{ form.email(class="form-control", placeholder="Username") }}
</div>
<div class="form-group">
{{ form.password(class="form-control", placeholder="Password") }}
</div>
<div class="form-group">
<button class="btn btn-default" type="submit">Sign In</button>
</div>
</form>
{% endblock %}
This way, there's no duplicate {% extend ... %}.
It now shows the form, but the WHOLE div is clickable, rendering it pretty much useless..
Any ideas?
You aren't supposed to have all the <html><head><body> tags in a child. It should just be:
{% extends "layout.html" %}
{% block container %}
<h3>aaa</h3>
<div class="collapse navbar-collapse" id="container">
{{ super() }}
<form action="{{ url_for('login')}}" class="navbar-form navbar-right" method="POST">
{{ form.hidden_tag() }}
<div class="form-group">
{{ form.email(class="form-control", placeholder="Username") }}
</div>
<div class="form-group">
{{ form.password(class="form-control", placeholder="Password") }}
</div>
<div class="form-group">
<button class="btn btn-default" type="submit">Sign In</button>
</div>
</form>
</div>
</div>
{% endblock %}
And notice how I moved the <h3>aaa</h3> code to inside the block.
Next, you can only have one {% extends ... %} call per rendering (You can't extend an extension). So, you need to consolidate your child to layout.html, making separate layouts per view.
Alternatively, you could change layout.html to use an include, keeping just one {% extends... %} per view:
layout.html
{% include "bootstrap/base.html" %}
{% block navbar %}
<nav class="navbar navbar-inverse navbar navbar-fixed-stop" role="navigation" style="border-radius:0px;">
<div class="container-fluid">
<div class="navbar-header"><a class="navbar-brand" href="#">BGP Monitor</a></div>
<ul class = "nav navbar-nav">
{% if g.user.is_authenticated %}
<li>Admin Panel</li>
{% endif %}
</ul>
<ul class="nav navbar-nav navbar-right">
{% if g.user.is_authenticated %}
<li><a href ="{{ url_for('logout') }}">Logout</li>
{% else %}
<li><a href ="{{ url_for('login') }}">Login</li>
{% endif %}
</ul>
</div>
</div>
</nav>
{% endblock %}
<div class="container-fluid" id="form">
{% block container %}{% endblock %}
</div>
Again, notice there are no duplicated <html> etc tags in layout.html. Those are already in bootstrap/base.html