silex loop one sql statement over another one - mysql

I have to get team members by their groups from a database.
My Database looks like:
table team_groups:
id
name
table team_member:
id
name
description
imagepath
team_group_id
I have an twig template where the team_members are shown by there groups like this:
<div class="row row-centered">
<h3 class="text-center">{{team_group.name}}</h3>
<div class="col-xs-6 col-centered col-fixed">
<div class="item">
<div class="team-member text-center">
<span><img class="img-team" src="{{ app.request.basepath }}/img/team/{{team_member.imagepath}}"
alt="{{team_member.name}}"></span>
<h3>{{team_member.name}}</h3>
<p>{{team_member.description}}</p>
</div>
</div>
</div>
<div class="col-xs-6 col-centered col-fixed">
<div class="item">
<div class="team-member text-center">
<span><img class="img-team" src="{{ app.request.basepath }}/img/team/{{team_member.imagepath}}"
alt="{{team_member.name}}"></span>
<h3>{{team_member.name}}</h3>
<p>{{team_member.description}}</p>
</div>
</div>
</div>
<div class="col-xs-6 col-centered col-fixed">
<div class="item">
<div class="team-member text-center">
<span><img class="img-team" src="{{ app.request.basepath }}/img/team/{{team_member.imagepath}}"
alt="{{team_member.name}}"></span>
<h3>{{team_member.name}}</h3>
<p>{{team_member.description}}</p>
</div>
</div>
</div>
</div>
But I don't know how to loop the team_members over the team_groups in my controller.
I started like that:
$teamGroups = $app['db']->fetchAll('SELECT * team_groups');
$teamMembers = $app['db']->fetchAll('SELECT * team_members');
but don't know how to continue.
Please help

Oh yeah twig is really nice...
I thought I have to link the objects in the controller, but now I simply wrote:
{% for teamGroup in teamGroups %}
<div class="row row-centered">
<h3 class="text-center">{{ teamGroup.name }}</h3>
{% for teamMember in teamMembers %}
{% if teamMember.team_group_id is same as(teamGroup.id) %}
<div class="col-xs-6 col-centered col-fixed">
<div class="item">
<div class="team-member text-center">
<span><img class="img-team" src="{{ app.request.basepath }}/img/team/{{ teamMember.image }}"
alt="{{ teamMember.name }}"></span>
<h3>{{ teamMember.name }}</h3>
<p>{{ teamMember.description }}</p>
</div>
</div>
</div>
{% endif %}
{% endfor %}
</div>
{% endfor %}
That did it for me :-)

Related

ERPNext Web Template - How to show specific category of Blog Posts

I want to show only a select/specific category of Blog Posts in Webpage Section added using the built in Page Builder.
Have created this Web Template in EPRNext to Show Blog postings on any WebPage by adding a Section using Page-Builder. This works fine to show the Blog Posts.
But I want to show only a select category of Posts. What should I add.
`
<section class="container my-5">
<h2 class="section-title">{{ _('जलक्रांतीच्या गाथा') }} </h2>
<p class="section-description">{{ _('ब्लॉगच्या माध्यमातुन') }} </p>
<div class="row">
{% for post in frappe.get_all("Blog Post", fields=["title", "blogger", "blog_intro", "route", "meta_image"], order_by="published_on desc", limit=6) %}
<div class="col-md-4 mb-4">
<div class="card h-100">
<img src={{ post.meta_image }} alt="" class="image-wiih-blur card-img-top image-loaded" max-width="400" max-height="400">
<div class="card-body">
<h5 class="card-title">{{ post.title }}</h5>
<p class="card-subtitle mb-2 text-muted">{{ _('By {0}').format(post.blogger) }}</p>
<p class="card-text">{{ post.blog_intro }}</p>
</div>
<div class="card-body flex-grow-0">
{{ _('पुढे वाचा') }}
</div>
</div>
</div>
{% endfor %}
</div>
</section>
`
<section class="container my-5">
<h2 class="section-title">{{ _('जलक्रांतीच्या गाथा') }} </h2>
<p class="section-description">{{ _('ब्लॉगच्या माध्यमातुन') }}</p>
{% set category = frappe.get_doc("Blog Category", selected_category_name) %}
<div class="row">
{% for post in frappe.get_all("Blog Post", fields=["title", "blogger", "blog_intro", "route", "meta_image"], filters={"blog_category": category.name}, order_by="published_on desc", limit=6) %}
<div class="col-md-4 mb-4">
<div class="card h-100">
<img src={{ post.meta_image }} alt="" class="image-wiih-blur card-img-top image-loaded" max-width="400" max-height="400">
<div class="card-body">
<h5 class="card-title">{{ post.title }}</h5>
<p class="card-subtitle mb-2 text-muted">{{ _('By {0}').format(post.blogger) }}</p>
<p class="card-text">{{ post.blog_intro }}</p>
</div>
<div class="card-body flex-grow-0">
{{ _('पुढे वाचा') }}
</div>
</div>
</div>
{% endfor %}
</div>
</section>

4 products on the same line in the template

I'm developing an e-commerce with Django. My backend is fine, my problem is with the template. Currently, I want to display 4 products per row, and if there are 7 products, the other 3 must be aligned with the top one. I'm using bootstrap to do this, however, for some reason I don't know, it doesn't have 4 products on the same line, even with space. I'm using a container with 1200px.
home.html
<div class="container">
<div class="row">
<div class="col-lg-8">
<div class="row">
{% for product in products %}
<div class="card mb-4 border rounded" style="width: 13.5rem;">
<a href="{{ product.get_absolute_url }}">
{%if product.image %}
<img class="img-produto" src='/media/{{product.image}}' class="card-img-top hover_img ">
{% else%}
<img class="img-produto" src="{% static '/img/not-found-product.jpg' %}" class="card-img-top hover_img">
{%endif%}
</a>
<div class="card-body">
<p class="card-title">{{product.name}}</p>
<p class="card-text"><i class='fas fa-dollar-sign' style="margin-right:2px"></i>{{product.price}}</p>
</div>
</div>
{% endfor %}
</div>
</div>
</div>
</div>
Just remove width: 13.5rem; and add class col-4 in the div. Like,
<div class="col-4 card mb-4 border rounded">
<!-- your content goes here -->
</div>

Can not see image during server side rendering in django

I can not see the image during server side rendering in django. Any help or hint would be appreciated. Below is the code I have written.
{% if object_list %}
{% for post in object_list %}
<div id="colorlib-main">
<section class="ftco-section ftco-no-pt ftco-no-pb">
<div class="container">
<div class="row d-flex">
<div class="col-xl-8 py-5 px-md-5">
<div class="row pt-md-4">
<div class="col-md-12">
<div class="d-md-flex">
<div class="text text-2 pl-md-4">
<h3 class="mb-2">{{post.title}}</h3>
<div class="meta-wrap">
<p class="meta">
<span><i class="icon-calendar mr-2"></i>June 28, 2019</span>
<span><i class="icon-folder-o mr-2"></i>Travel</span>
<span><i class="icon-comment2 mr-2"></i>5 Comment</span>
</p>
</div>
<p class="mb-4">A small river named Duden flows by their place and supplies it with the necessary regelialia.</p>
<p>Read More <span class="ion-ios-arrow-forward"></span></p>
</div>
</div>
</div>
</div>
{% endfor %}
{% else %}
<p>No post yet!!</p>
{% endif %}
Any clue/hint?

Have liquid syntax include an additional liquid syntax?

I am trying to refactor my site using the D.R.Y. method, part of that is using liquid syntax to help.
Currently everything works with what I have here:
page-internal.html
---
layout: default
<div>
<div class="d-flex" style="background-color: #e9ecef;">
<div class="jumbotron mx-auto mb-0 py-3 px-5" style="max-width: 1200px">
<div class="col-lg-12 p-3 mx-auto">
<img width="50" height="50"
class="rounded-circle float-left mr-2"
src="/assets/img/internal/{{ page.image }}" />
<h1 class="display-4">{{ page.title | escape }}</h1>
<p class="lead">{{ content }}</p>
</div>
</div>
</div>
<div>
<div class="d-flex justify-content-center">
{% include card-post-{{ page.passname }}.html %}
</div>
</div>
</div>
The {{ page.passname }} pulls from a .md file like so:
---
layout: page-internal
title: User Interface
permalink: /pages/design-ui
image: ui.svg
passname: ui
---
That works just fine, too. But then I have to create several pages to pull from instead of just referencing passname to grab the right .md page (I hope I'm making sense here, apologies if I'm not). That page looks like this
card-post.ui.html
And the html on that page is:
<div class="container-fluid">
<div class="col-lg-12 mx-auto row d-flex justify-content-center mt-3" style="max-width: 1400px">
{% for post in site.categories.ui %}
<div class="card col-sm-12 col-lg-3 m-2">
<div class="card-body d-flex flex-column">
<div class="media">
<div class="d-flex mr-3">
<a href="{{ post.url }}">
<img width="40" height="40"
class="rounded-circle"
src="/assets/img/{{ post.image }} " alt="{{ post.title }}" />
</a>
</div>
<div class="media-body">
<h6 class="mb-1">{{ post.title }}</h6>
</div>
</div>
<div class="d-flex flex-column" style="height: 105px;">
<div class="p-2">
<p class="text-muted">{{ post.excerpt }}</p>
</div>
</div>
<div class=" flex-column align-items-end">
<button type="button" class="btn btn-secondary btn-sm btn-block" onclick="location.href = '{{ post.url }}';">View project</button>
</div>
</div>
</div>
{% endfor %}
</div>
</div>
What I'd like to do is take the two html sites and have it like this:
---
layout: default
---
<div>
<div class="d-flex" style="background-color: #e9ecef;">
<div class="jumbotron mx-auto mb-0 py-3 px-5" style="max-width: 1200px">
<div class="col-lg-12 p-3 mx-auto">
<img width="50" height="50"
class="rounded-circle float-left mr-2"
src="/assets/img/internal/{{ page.image }}" />
<h1 class="display-4">{{ page.title | escape }}</h1>
<p class="lead">{{ content }}</p>
</div>
</div>
</div>
<div>
<div class="d-flex justify-content-center">
{% include card-post-{{ page.passname }}.html %}
<div class="container-fluid">
<div class="col-lg-12 mx-auto row d-flex justify-content-center mt-3" style="max-width: 1400px">
{% for post in site.categories.ui %}
<div class="card col-sm-12 col-lg-3 m-2">
<div class="card-body d-flex flex-column">
<div class="media">
<div class="d-flex mr-3">
<a href="{{ post.url }}">
<img width="40" height="40"
class="rounded-circle"
src="/assets/img/{{ post.image }} " alt="{{ post.title }}" />
</a>
</div>
<div class="media-body">
<h6 class="mb-1">{{ post.title }}</h6>
</div>
</div>
<div class="d-flex flex-column" style="height: 105px;">
<div class="p-2">
<p class="text-muted">{{ post.excerpt }}</p>
</div>
</div>
<div class=" flex-column align-items-end">
<button type="button" class="btn btn-secondary btn-sm btn-block" onclick="location.href = '{{ post.url }}';">View project</button>
</div>
</div>
</div>
{% endfor %}
</div>
</div>
</div>
</div>
</div>
This would work however the syntax here:
{% for post in site.categories.ui %}
Needs to be (and this is where I can't figure out what to do)
{% for post in site.categories. {{ page.passname }} %}
This throws an error:
Liquid Warning: Liquid syntax error (line 23): Unexpected character { in "post in site.categories.{{ page.passname }}" in /_layouts/page-internal.html
So my question is, how can I get the passname from said .md post (in this instance it'd be design-ui.md ) and put it into {% for post in site.categories.ui %} where the word ui would be dependint on the .md
I hope I said all this right, apologies if not.
Your loop syntax {% for post in site.categories. {{ page.passname }} %}
is incorrect :
You may reach your category with bracket notation :
{% for post in site.categories[page.passname] %}

How to make columns not dependent on each other with Bootstrap?

There is a menu on the left with the effect of the accordion, on the right content is formed with a jinja. I need to do so that the height of the menu and the contents do not depend on each other.
as here: click
HTML:
<!-- menu -->
<div class="col-md-3">
<div class="wrapper">
<h1 class="header-tabs">Brands</h1>
<div class="tab">
{% for brand in brands %}
<button value="{{ brand.id }}">{{ brand.brand_name }
</button>
{% endfor %}
</div>
</div>
</div>
<!-- content -->
{% for sm in smartphones %}
<div class="col-md-2">
<img class="photo-phone" height="150" width="150" src="{{ sm.photo.url }}">
</div>
<div class="col-md-5">
<h3 class="header-phone">{{ sm.brand }} {{ sm.model }}</h3>
<p descr-phone>{{ sm.description }}</p>
</div>
<div class="col-md-2">
<h4 class="price">{{ sm.price }}$</h4>
<input type="button" class="button-buy" value="Buy">
</div>
{% endfor %}
The usual way to achieve that is by nesting. Nesting must always be done using row-column pairs i.e. never nest a column directly inside another column.
So, in your case, you'd first create a column with the class col-md-9 then put a .row inside that column and then put all your content columns inside that newly created row.
Note that inside this newly created row you now have a total of 12 column units to work with.
Click "run code snippet" below and expand to full page for testing:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="container">
<div class="row">
<!-- menu -->
<div class="col-md-3">
<div class="wrapper">
<h1 class="header-tabs">Brands:</h1>
<div class="tab">
<!-- {% for brand in brands %}-->
<button value="{{ brand.id }}">
<!-- {{ brand.brand_name }-->
Brand Name
</button>
<!-- {% endfor %}-->
</div>
</div>
</div>
<!-- content -->
<div class="col-md-9">
<div class="row">
<!-- {% for sm in smartphones %}-->
<div class="col-md-3 mb-3">
<!-- <img class="photo-phone" height="150" width="150" src="{{ sm.photo.url }}">-->
<img class="photo-phone img-fluid" src="https://placeimg.com/640/480/tech">
</div>
<div class="col-md-6">
<h3 class="header-phone">
<!-- {{ sm.brand }} {{ sm.model }}-->
Brand Model
</h3>
<p descr-phone>
<!-- {{ sm.description }}-->
Description
</p>
</div>
<div class="col-md-3 mb-3">
<h4 class="price">
<!-- {{ sm.price }}$-->
$1,000
</h4>
<input type="button" class="button-buy" value="Buy">
</div>
<div class="col-md-3 mb-3">
<!-- <img class="photo-phone" height="150" width="150" src="{{ sm.photo.url }}">-->
<img class="photo-phone img-fluid" src="https://placeimg.com/640/480/tech">
</div>
<div class="col-md-6">
<h3 class="header-phone">
<!-- {{ sm.brand }} {{ sm.model }}-->
Brand Model
</h3>
<p descr-phone>
<!-- {{ sm.description }}-->
Description
</p>
</div>
<div class="col-md-3 mb-3">
<h4 class="price">
<!-- {{ sm.price }}$-->
$1,000
</h4>
<input type="button" class="button-buy" value="Buy">
</div>
<div class="col-md-3 mb-3">
<!-- <img class="photo-phone" height="150" width="150" src="{{ sm.photo.url }}">-->
<img class="photo-phone img-fluid" src="https://placeimg.com/640/480/tech">
</div>
<div class="col-md-6">
<h3 class="header-phone">
<!-- {{ sm.brand }} {{ sm.model }}-->
Brand Model
</h3>
<p descr-phone>
<!-- {{ sm.description }}-->
Description
</p>
</div>
<div class="col-md-3 mb-3">
<h4 class="price">
<!-- {{ sm.price }}$-->
$1,000
</h4>
<input type="button" class="button-buy" value="Buy">
</div>
<!-- {% endfor %}-->
</div>
</div>
</div>
</div>
Also note the use of the spacing class mb-3 (margin-bottom 3 units).
The img-fluid class makes the images responsive.
Reference:
https://getbootstrap.com/docs/4.0/layout/grid/#nesting