Validation of checkbox in Shopware 6 only working upon up and down scroll - twig-extension

I moved the terms and conditions consent from the original twig template so that it shows at a different position on the website. My problem is that when the consent checkbox is not checked, a warning should be shown to the user when clicking the payment button. This however only happens, when scrolling up and down on the website after clicking the finish payment button. Does anyone see my mistake?
{% sw_extends '#Storefront/storefront/page/checkout/confirm/index.html.twig' %}
{% block base_header %}
{% sw_include '#Storefront/storefront/layout/header/header-minimal.html.twig' %}
{% endblock %}
{% block base_navigation %}{% endblock %}
{% block page_checkout_main_content %}
{% block page_checkout_confirm %}
{% block page_checkout_confirm_header %}
<h1 class="confirm-main-header">
{{ "checkout.confirmHeader"|trans|sw_sanitize }}
</h1>
{% endblock %}
{% block page_checkout_confirm_alerts %}
{% block page_checkout_confirm_violations %}
{% for violation in formViolations.getViolations() %}
{% set snippetName = "error.#{violation.code}" %}
{% set fieldName = violation.propertyPath|trim('/', 'left') %}
{% sw_include '#Storefront/storefront/utilities/alert.html.twig' with {
type: "danger",
content: snippetName|trans({'%field%': fieldName})|sw_sanitize
} %}
{% endfor %}
{% endblock %}
{% endblock %}
{% block page_checkout_confirm_address %}
<div class="confirm-address">
{% sw_include '#Storefront/storefront/page/checkout/confirm/confirm-address.html.twig' %}
</div>
{% endblock %}
{% block page_checkout_confirm_payment_shipping %}
<div class="confirm-payment-shipping">
<div class="row">
{% block page_checkout_confirm_payment %}
<div class="col-sm-6 confirm-payment">
{% sw_include '#Storefront/storefront/page/checkout/confirm/confirm-payment.html.twig' %}
</div>
{% endblock %}
{% block page_checkout_confirm_shipping %}
<div class="col-sm-6 confirm-shipping">
{% sw_include '#Storefront/storefront/page/checkout/confirm/confirm-shipping.html.twig' %}
</div>
{% endblock %}
</div>
</div>
{% endblock %}
{% block page_checkout_confirm_product_table %}
<div class="confirm-product">
{% block page_checkout_confirm_table_container %}
<div class="card">
<div class="card-body">
{% block page_checkout_confirm_table_header %}
{% sw_include '#Storefront/storefront/page/checkout/confirm/confirm-product-header.html.twig' %}
{% endblock %}
{% block page_checkout_confirm_table_items %}
{% for lineItem in page.cart.lineItems %}
{% block page_checkout_confirm_table_item %}
{% sw_include '#Storefront/storefront/page/checkout/confirm/confirm-item.html.twig' %}
{% endblock %}
{% endfor %}
{% endblock %}
</div>
</div>
{% endblock %}
</div>
{% endblock %}
{% block page_checkout_confirm_tos %}
<div class="confirm-tos">
<div class="card checkout-card">
<div class="card-body">
{% block page_checkout_confirm_tos_header %}
<div class="card-title">
{{ "checkout.confirmTermsHeader"|trans|sw_sanitize }}
</div>
{% endblock %}
{% block page_checkout_confirm_revocation_notice %}
{% if config('confirm.revocationNotice') %}
<p class="revocation-notice">
{% block page_checkout_confirm_revocation_notice_link %}
<a href="{{ path('frontend.cms.page',{ id: config('core.basicInformation.revocationPage') }) }}"
{{ dataBsToggleAttr }}="modal"
title="{{ "checkout.confirmRevocationNotice"|trans|striptags }}"
data-url="{{ path('frontend.cms.page',{ id: config('core.basicInformation.revocationPage') }) }}">
{{ "checkout.confirmRevocationNotice"|trans|sw_sanitize }}
</a>
{% endblock %}
</p>
{% endif %}
{% endblock %}
{% block page_checkout_confirm_tos_control %}
<div class="{{ formCheckboxWrapperClass }}">
{% block page_checkout_confirm_tos_control_checkbox %}
<input type="checkbox"
class="checkout-confirm-tos-checkbox {{ formCheckInputClass }}{% if formViolations.getViolations('/tos') is not empty %} is-invalid{% endif %}"
required="required"
id="tos"
form="confirmOrderForm"
name="tos"/>
{% endblock %}
{% block page_checkout_confirm_tos_control_label %}
<label for="tos"
class="checkout-confirm-tos-label custom-control-label">
{{ "checkout.confirmTerms"|trans({
'%url%': path('frontend.cms.page',{ id: config('core.basicInformation.tosPage') })
})|raw }}
</label>
{% endblock %}
</div>
{% endblock %}
</div>
</div>
</div>
{% endblock %}
{% block page_checkout_confirm_hidden_line_items_information %}
{% sw_include '#Storefront/storefront/component/checkout/hidden-line-items-information.html.twig' with {
cart: page.cart,
lineItems: page.cart.lineItems
} %}
{% endblock %}
{% endblock %}
{% endblock %}
{% block page_checkout_additional %}
{% if config('core.cart.showCustomerComment') %}
<div class="checkout-additional">
{% block page_checkout_finish_customer_comment %}
<div class="card checkout-card">
<div class="card-body">
{% block page_checkout_confirm_customer_comment_header %}
<div class="card-title">
{{ "checkout.customerCommentHeader"|trans|sw_sanitize }}
</div>
{% endblock %}
{% block page_checkout_confirm_customer_comment_control %}
<div class="checkout-customer-comment-control">
{% block page_checkout_confirm_customer_comment_control_textfield_label %}
<label class="form-label" for="{{ constant('Shopware\\Core\\Checkout\\Order\\SalesChannel\\OrderService::CUSTOMER_COMMENT_KEY') }}">
{{ "checkout.customerCommentLabel"|trans|sw_sanitize }}
</label>
{% endblock %}
{% block page_checkout_confirm_customer_comment_control_textfield %}
<textarea class="form-control"
placeholder="{{ "checkout.customerCommentPlaceholder"|trans|sw_sanitize }}"
id="{{ constant('Shopware\\Core\\Checkout\\Order\\SalesChannel\\OrderService::CUSTOMER_COMMENT_KEY') }}"
form="confirmOrderForm"
name="{{ constant('Shopware\\Core\\Checkout\\Order\\SalesChannel\\OrderService::CUSTOMER_COMMENT_KEY') }}"></textarea>
{% endblock %}
</div>
{% endblock %}
</div>
</div>
{% endblock %}
</div>
{% endif %}
{% endblock %}
{% set formAddHistoryOptions = {
entries: [{
state: {},
title: 'account.ordersTitle'|trans,
url: path('frontend.account.order.page')
}]
} %}
{% block page_checkout_aside_actions %}
<div class="checkout-aside-action">
<form id="confirmOrderForm"
action="{{ path('frontend.checkout.finish.order') }}"
data-form-csrf-handler="true"
data-form-preserver="true"
data-form-submit-loader="true"
data-form-add-history="true"
data-form-add-history-options='{{ formAddHistoryOptions|json_encode }}'
method="post">
{% block page_checkout_aside_actions_csrf %}
{{ sw_csrf('frontend.checkout.finish.order') }}
{% endblock %}
{% block page_checkout_confirm_form_submit %}
{# #deprecated tag:v6.5.0 - Bootstrap v5 removes `btn-block` class, use `d-grid` wrapper instead #}
{% if feature('v6.5.0.0') %}
<div class="d-grid">
<button id="confirmFormSubmit"
class="btn btn-primary btn-lg"
form="confirmOrderForm"
{% if page.cart.errors.blockOrder %}
disabled
{% endif %}
type="submit">
{{ "checkout.confirmSubmit"|trans|sw_sanitize }}
</button>
</div>
{% else %}
<button id="confirmFormSubmit"
class="btn btn-primary btn-block btn-lg"
form="confirmOrderForm"
{% if page.cart.errors.blockOrder %}
disabled
{% endif %}
type="submit">
{{ "checkout.confirmSubmit"|trans|sw_sanitize }}
</button>
{% endif %}
{% endblock %}
</form>
</div>
{% endblock %}
{% block base_footer %}
{% sw_include '#Storefront/storefront/layout/footer/footer-minimal.html.twig' %}
{% endblock %}

Related

Using a custom form inside django wizard

How would I use a custom form to display inside the session wizard so when it goes through each step it displays the html for each form inside the signup.html.
createUser.html
{% extends 'base.html' %}
{% block title %}Create User{% endblock %}
{% block content %}
<form method="POST" action='.' enctype="multipart/form-data">
{% csrf_token %}
<!-- A formwizard needs this form -->
{{ wizard.management_form }}
{% for field in form %}
<p>
{{ field.label_tag }}<br>
{{ field }}
{% if field.help_text %}
<small style="color: grey">{{ field.help_text }}</small>
{% endif %}
{% for error in field.errors %}
<p style="color: red">{{ error }}</p>
{% endfor %}
</p>
{% endfor %}
<button>Sign up</button>
<button>Log In</button>
</form>
{% endblock %}
views.py
class UserWizard(SessionWizardView):
template_name = "registration/signup.html"
form_list = [SignUpForm]
def done(self, form_list, **kwargs):
process_data(form_list)
return redirect('home')
signup.html
{% extends 'base.html' %}
{% load i18n %}
{% block head %}
{{ wizard.form.media }}
{% endblock %}
{% block title %}Sign up{% endblock %}
{% block content %}
<h2>Sign up</h2>
<p>Step {{ wizard.steps.step1 }} of {{ wizard.steps.count }}</p>
<form action="." method="POST" enctype="multipart/form-data">
{% csrf_token %}
<table>
{{ wizard.management_form }}
{% if wizard.form.forms %}
{{ wizard.form.management_form }}
{% for form in wizard.form.forms %}
{{ form }}
{% endfor %}
{% else %}
{{ wizard.form }}
{% endif %}
</table>
{% if wizard.steps.prev %}
<button name="wizard_goto_step" type="submit" value="{{ wizard.steps.prev }}">{% trans "prev step" %}</button>
{% endif %}
<input type="submit" value="{% trans 'submit' %}"/>
</form>
{% endblock %}

Django Block Code doesn't render

doing a site and i need some help with the block tags. It seems that django doesn't render {% block home %} {%endblock home %}. Let's suppose in my block code i have this div and if i put the div inside my base.html as per below example it doesn't appear. It appears only when i put the source code inside the base.html, so is not including my tags. What should i do? PS i have the extended code in my block e.g. {% extends "base.html" %}
<div>
<H1>Aici trebuie adaugat restul</H1>
</div>
My base.html:
{% load staticfiles %}
<!--DOCTYPE html -->
<html>
<head>
<title>{% block head_title %}Advancing the Blog{% endblock head_title %}</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css' >
<link rel='stylesheet' href='{% static "css/base.css" %}' />
<style>
{% block style %}{% endblock style %}
</style>
{% block head_extra %} {% endblock head_extra %}
</head>
<body>
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.5";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
{% include "messages_display.html" %}
<div class='container'>
<ol class='breadcrumb'>
<li><a href='{% url "posts:list" %}'>Home</a></li>
{% block post_detail_link %}
{% endblock %}
<!-- {% block index %}
{% endblock %} -->
{% if not request.user.is_authenticated %}
<li class='pull-right'><a href='{% url "register" %}'>Register</a></li>
<li class='pull-right'><a href='{% url "login" %}'>Login</a></li>
{% else %}
<li class='pull-right'><a href='{% url "logout" %}'>Logout</a></li>
{% endif %}
</ol>
<div>
<H1>Aici trebuie adaugat restul</H1>
</div>
{% block home %} {%endblock home %}
{% block content %}{% endblock content %}
</div>
<!-- Latest compiled and minified JavaScript -->
<script src="http://code.jquery.com/jquery-1.12.2.min.js" integrity="sha256-lZFHibXzMHo3GGeehn1hudTAP3Sc0uKXBXAzHX1sjtk=" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/marked/0.3.5/marked.min.js'></script>
<script type="text/javascript">
$(document).ready(function(){
$(".content-markdown").each(function(){
var content = $(this).text()
var markedContent = marked(content)
$(this).html(markedContent)
})
$(".post-detail-item img").each(function(){
$(this).addClass("img-responsive");
})
var contentInput = $("#id_content");
function setContent(value){
var markedContent = marked(value)
$("#preview-content").html(markedContent)
$("#preview-content img").each(function(){
$(this).addClass("img-responsive")
})
}
setContent(contentInput.val())
contentInput.keyup(function(){
var newContent = $(this).val()
setContent(newContent)
})
var titleInput = $("#id_title");
function setTitle(value) {
$("#preview-title").text(value)
}
setTitle(titleInput.val())
titleInput.keyup(function(){
var newContent = $(this).val()
setTitle(newContent)
})
$(".comment-reply-btn").click(function(event){
event.preventDefault();
$(this).parent().next(".comment-reply").fadeToggle();
})
// preview-title
// preview-content
})
</script>
</body>
</html>
comment_thread.html
{% extends "base.html" %}
{% load urlify %}
{% load crispy_forms_tags %}
{% block head_title %}
{{ instance.title }} | {{ block.super }}
{% endblock head_title %}
<H1>TEST </H1>
{% block content %}
{{ object }}
<div class='col-sm-6 col-sm-offset-3'>
<p>{{ comment.content }}</p>
<footer>via {{ comment.user }} | {{ comment.timestamp|timesince }} ago | {% if comment.children.count > 0 %}{{ comment.children.count }} Comment{% if comment.children.count > 1 %}s{% endif %} {% endif %} {% if request.user == comment.user %}<a href='{{ comment.get_delete_url }}'>Delete</a> {% endif %}</footer>
<hr/>
<div>
{% for child_comment in comment.children %}
<blockquote>
<p>{{ child_comment.content }}</p>
<footer>via {{ child_comment.user }} | {{ child_comment.timestamp|timesince }} ago | {% if request.user == child_comment.user %}<a href='{{ child_comment.get_delete_url }}'>Delete</a>{% endif %}</footer>
</blockquote>
{% endfor %}
{% if request.user.is_authenticated %}
<form method="POST" action="."> {% csrf_token %}
{{ form|crispy }}
<input type='hidden' name='parent_id' value='{{ comment.id }}'>
<input type='submit' value='Reply' class='btn btn-default'>
</form>
{% else %}
<p>You must login to comment </p>
{% endif %}
</div>
<hr/>
</div>
{% endblock content %}
confirm_delete.html
{% extends "base.html" %}
{% load urlify %}
{% load crispy_forms_tags %}
{% block head_title %}
{{ instance.title }} | {{ block.super }}
{% endblock head_title %}
{% block content %}
<div class='col-sm-6 col-sm-offset-3'>
<h1>Confirm Delete</h1>
<form method="POST" action="."> {% csrf_token %}
<p>A re you sure you want to delete: "{{ object.content }}"?</p>
<input type='submit' value='Confirm' class='btn btn-warning'>
<a href='{{ object.get_absolute_url }}' class='btn btn-default'>Cancel</a>
</form>
</div>
<hr/>
</div>
{% endblock content %}
form.html
{% extends "base.html" %}
{% load crispy_forms_tags %}
{% block content %}
<!-- {% block index_home %}
{% endblock %} -->
<div class='col-sm-6 col-sm-offset-3'>
<h1>{{ title }}</h1>
<hr/>
<form method='POST' action='' enctype='multipart/form-data'>{% csrf_token %}
{{ form|crispy }}
<input type='submit' class='btn btn-default' value='{{ title }}' />
</form>
</div>
{% endblock content %}
messages_display.html
{% if messages %}
<div class='messages'>
<ul class="messages">
{% for message in messages %}
<li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{% if "html_safe" in message.tags %}{{ message|safe }}{% else %}{{ message }}{% endif %}</li>
{% endfor %}
</ul>
</div>
{% endif %}
post_detail.html
{% extends "base.html" %}
{% load urlify %}
{% load crispy_forms_tags %}
{% block head_title %}
{{ instance.title }} | {{ block.super }}
{% endblock head_title %}
{% block post_detail_link %}
<li><a href='{{ instance.get_absolute_url }}'>{{ instance.title }}</a></li>
{% endblock %}
{% block content %}
<div class='col-sm-6 col-sm-offset-3'>
{% if instance.image %}
<img src='{{ instance.image.url }}' class='img-responsive' />
{% endif %}
<h1>{{ title }} <small>{% if instance.draft %}<span style='color:red;'>Draft</span> {% endif %}{{ instance.publish }}</small></h1>
<!-- {% if instance.read_time|time:"i" <= "01" %} < 1 minute {% else %}{{ instance.read_time|time:"i" }} minutes {% endif %} -->
<p>Read time: {% if instance.read_time <= 1 %} < 1 Minute {% else %}{{ instance.read_time }} minutes {% endif %}</p>
{% if instance.user.get_full_name %}
<p>Author: {{ instance.user.get_full_name }}</p>
{% endif %}
<p><div class="fb-like" data-href="{{ request.build_absolute_uri }}" data-layout="button_count" data-action="like" data-show-faces="true" data-share="true"></div>
<hr/>
</p>
<p>
<a href="https://www.facebook.com/sharer/sharer.php?u={{ request.build_absolute_uri }}">
Facebook
</a>
<a href="https://twitter.com/home?status={{ instance.content|truncatechars:80|urlify }}%20{{ request.build_absolute_uri }}">
Twitter
</a>
<a href='https://plus.google.com/share?url={{ request.build_absolute_uri }}'>
<a href="https://www.linkedin.com/shareArticle?mini=true&url={{ request.build_absolute_uri }}&title={{ instance.title }}&summary={{ share_string }}&source={{ request.build_absolute_uri }}">
Linkedin
</a>
Reddit
</p>
<div class='row'>
<div class='col-sm-12 '>
<div class='post-detail-item'>{{ instance.get_markdown }}</div>
<hr/>
<br/>
<div>
<p class='lead'>Comments</p>
{% if request.user.is_authenticated %}
<form method="POST" action="."> {% csrf_token %}
{{ comment_form|crispy }}
<input type='submit' value='Post comment' class='btn btn-default'>
</form>
{% else %}
<p>You must login to comment </p>
{% endif %}
<hr/>
{% for comment in comments %}
<blockquote>
<p>{{ comment.content }}</p>
<footer>via {{ comment.user }} | {{ comment.timestamp|timesince }} ago | {% if comment.children.count > 0 %}{{ comment.children.count }} Comment{% if comment.children.count > 1 %}s{% endif %} | {% endif %} <a class='comment-reply-btn' href='#'>Reply</a> | <a class='' href='{{ comment.get_absolute_url }}'>Thread</a></footer>
<div class='comment-reply'>
{% for child_comment in comment.children %}
<blockquote>
<p>{{ child_comment.content }}</p>
<footer>via {{ child_comment.user }} | {{ child_comment.timestamp|timesince }} ago</footer>
</blockquote>
{% endfor %}
{% if request.user.is_authenticated %}
<form method="POST" action="."> {% csrf_token %}
{{ comment_form|crispy }}
<input type='hidden' name='parent_id' value='{{ comment.id }}'>
<input type='submit' value='Reply' class='btn btn-default'>
</form>
{% else %}
<p>You must login to comment </p>
{% endif %}
</div>
</blockquote>
<hr/>
{% endfor %}
</div>
</div>
</div>
</div>
{% endblock content %}
post_form.html
{% extends "base.html" %}
{% load crispy_forms_tags %}
{% block head_extra %}
{{ form.media }}
{% endblock head_extra %}
{% block content %}
<div class='col-sm-6'>
<h1>Preview</h1>
<hr/>
<div class='content-preview'>
<h3 id='preview-title'></h3>
<p id='preview-content'></p>
</div>
</div>
<div class='col-sm-6'>
<h1>Form</h1>
<hr/>
<form method='POST' action='' enctype='multipart/form-data'>{% csrf_token %}
{{ form|crispy }}
<input type='submit' class='btn btn-default' value='Create Post' />
</form>
</div>
{% endblock content %}
post_list.html
{% extends "base.html" %}
{% block content %}
<div class='col-sm-6 col-sm-offset-3'>
<h1>{{ title }}</h1>
<form method='GET' action='' class='row'>
<div class='col-sm-6'>
<div class='input-group'>
<input class='form-control' type='text' name='q' placeholder='Search posts' value='{{ request.GET.q }}'/>
<span class='input-group-btn'>
<!-- <input class='btn btn-default' type='submit' value='Search' /> -->
<button class='btn btn-default' type='submit'>Search <i class="fa fa-search"></i></button>
</span>
</div>
</div>
</form>
{% for obj in object_list %}
<div class="row">
<div class="col-sm-12">
<div class="thumbnail">
{% if obj.image %}
<img src='{{ obj.image.url }}' class='img-responsive' />
{% endif %}
<div class="caption post-detail-item">
{% if obj.draft %}<h3>Staff only: Draft</h3>{% endif %} {% if obj.publish > today %}<h3>Staff Only: Future Post</h3>{% endif %}
<h3><a href='{{ obj.get_absolute_url }}'>{{ obj.title }}</a> <small>{{ obj.publish }}</small></h3>
{% if obj.user.get_full_name %}<p>Author: {{ obj.user.get_full_name }}</p>{% endif %}
{{ obj.get_markdown|truncatechars_html:120 }}
<p>View</p>
</div>
</div>
</div>
<hr/>
</div>
{% endfor %}
<div class="pagination">
<span class="step-links">
{% if object_list.has_previous %}
previous
{% endif %}
<span class="current">
Page {{ object_list.number }} of {{ object_list.paginator.num_pages }}.
</span>
{% if object_list.has_next %}
next
{% endif %}
</span>
</div>
</div>
{% endblock content %}
Could you try having {% endblock home %} instead of {%endblock home %}. The lack of space can sometimes mess things up.
If this does not work, try simply have {% endblock %} instead.
Hope this helps!

Custom menu in Mezzanine

I have following mezzanine tree.html
{% if page_branch_in_menu %}
<ul class="nav nav-list navlist-menu-level-{{ branch_level }}">
{% for page in page_branch %}
{% if page.in_menu %}
{% if page.is_current_or_ascendant or not page.is_primary %}
<li class="
{% if page.is_current %} active{% endif %}
{% if page.is_current_or_ascendant %} active-branch{% endif %}
" id="tree-menu-{{ page.html_id }}">
{{ page.title }}
{% if page.has_children_in_menu %}{% page_menu page %}{% endif %}
</li>
{% endif %}
{% endif %}
{% endfor %}
</ul>
{% endif %}
In the base.html I have following block:
<div class="col-md-2 left">
{% block left_panel %}
<div class="panel panel-default tree">{% page_menu "pages/menus/tree.html" %}</div>
{% endblock %}
</div>
The problem is that on some pages where the menu is empty the css styles are applied to the divs with empty menu lists and users can observe empty containers. In html it looks like:
<div class="col-md-2 left">
<div class="panel panel-default tree">
<ul class="nav nav-list navlist-menu-level-0"></ul>
</div>
</div>
I can hide the child ul with something like .nav:empty { display:none;} but the parent will still be visible. Here is the discussion about similar question: :empty selector for parent element
Is it possible to solve this problem with Mezzanine template tags?
{% if page_branch %} doesn't help because it's full of pages which are all not in_menu.
So better filter them before context.
menu_pages = page_branch.filter(in_menu=True)
Also you should put if block on top of div.tree
{% if menu_pages %}
<div class="panel panel-default tree">{% page_menu "pages/menus/tree.html" %}</div>
{% endif %}
Another way is to write custom filter
{% with menu_pages=page_branch|filter_in_menu %}
{% if menu_pages %}
...
{% endif %}
{% endif %}
But there is no way to apply extra filter to queryset with built-in syntax or Mezzanine tags.
You could wrap the code with an if tag.
{% if page_branch %}
<ul>
{% for page in page_branch %}
{% if page.in_menu %}
{% if page.is_current_or_ascendant or not page.is_primary %}
<li>
{% if not page.is_primary %}
{{ page.title }}
{% endif %}
{% page_menu page %}
</li>
{% endif %}
{% endif %}
{% endfor %}
</ul>
{% endif %}

MultiValueDictKeyError

I have the following code. The first works, however the second throws a "MultiValueDictKeyError". I've tweaked the code around a bit but I haven't been able to fix it. Any and all help is greatly appreciated!
Working Code:
{% extends "base.html" %}
{% block base_content %}
<link rel="stylesheet" href="/media/themes/txt/css/employee_summary/report.css" />
<form id="myForm" method="post">
{% csrf_token %}
{% for field in form %}
<div class=box>
<div class="row">
<div class="2u">
<h1>{{ field.label_tag }}:</h1>
</div>
<div class="10u">
{{ field }}
</div>
</div>
</div>
{% endfor %}
{% for formset in inlines %}
<div class=box>
{% for form in formset %}
<div class="row">
<div class="12u">
<h1>{{ form }}</h1>
</div>
</div>
{% endfor %}
</div>
{% endfor %}
{% for formset in inlines %}
{{ formset.management_form }}
{% endfor %}
<input type="submit" value="Save Changes">
</form>
{% endblock %}
Non-Working Code:
{% extends "base.html" %}
{% block base_content %}
<link rel="stylesheet" href="/media/themes/txt/css/employee_summary/report.css" />
<div id="main-wrapper">
<div class="strongborder">
<div id="main" class="container boldtext">
<form id="myForm" method="post" class="12u">
{% csrf_token %}
{% for field in form %}
<div class="row">
<div class="2u">
<h1>{{ field.label_tag }}:</h1>
</div>
<div class="10u">
{{ field }}
</div>
</div>
{% endfor %}
{% for formset in inlines %}
{% for form in formset %}
<br>
<br>
<h1>{{ form.instance.form_name }}</h1>
{% for field in form %}
<div class="row">
{% if field.label != "Employee" and field.label != "Id" and field.label != "Delete" %}
<label class="2u">{{ field.label }}:</label>
<div class="10u">{{ field }}</div>
{% endif %}
</div>
{% endfor %}
{% endfor %}
{% endfor %}
{% for formset in inlines %}
{{ formset.management_form }}
{% endfor %}
<br>
<br>
<input type="submit" value="Save Changes">
</form>
</div>
</div>
</div>
{% endblock %}
Solved by myself: for some reason it wasn't liking the ID skip in
{% if field.label != "Employee" and field.label != "Id" and field.label != "Delete" %}
... yet it was fine with skipping the employee and delete fields.

Django template include a template with a variable coming from view

I have problem with Django templates. I want to create a base html, which I will use to display posts. I call a template from view, which includes an html file, where the file extends the base html.
view
def main(request):
all_posts = News.objects.all()
return render_to_response("index.html", {'all_posts': all_posts})
template -- index.html
<div id="content">
{% include 'content.html' with posts=all_posts%}
</div>
content.html
{% extends "content_base.html" %}
{% for post in posts %}
{% block date_of_post %} {{ post.date }} {% endblock %}
{% block post_author %} {{ post.author }} {% endblock %}
{% block post %} {{ post.content }} {% endblock %}
{% endfor %}
content_base.html
<div class="post">
<h2 class="title">{% block blabla %}{% endblock %}</h2>
<p class="meta"><span class="date">{% block date_of_post %}{% endblock %}</span><span class="posted">Posted by {% block post_author %}{% endblock %}</span></p>
<div style="clear: both;"> </div>
<div class="entry">
<p>
{% block post %} {% endblock %}
</p>
<p class="links">
Read More
Comments
</p>
</div>
</div>
But it seems like I cannot pass the *all_posts* variable to content.html. What is the problem here? Am I doing something wrong?
Thanks in advance.
You should move the loop into index.html, and include content_base.html directly. So index.html becomes:
<div id="content">
{% for post in posts %}
{% include 'content_base.html' %}
{% endfor %}
</div>
and content_base.html is
<div class="post">
<h2 class="title">{{ post.title }}</h2>
<p class="meta"><span class="date">{{ post.date }}</span><span class="posted">Posted by {{{ post.author }}</span></p>
<div style="clear: both;"> </div>
<div class="entry">
<p>
{{ post.content }}
</p>
<p class="links">
Read More
Comments
</p>
</div>
</div>
You're using blocks with identical names, because you're using them in a loop:
{% for post in posts %}
{% block date_of_post %} {{ post.date }} {% endblock %}
{% block post_author %} {{ post.author }} {% endblock %}
{% block post %} {{ post.content }} {% endblock %}
{% endfor %}
You can't do that. Look here.
Sometimes too much normalization is not so good. You can simply have index.html and all of your code can go there (avoiding unnecessary blocks).
<div id="content">
{% for post in all_posts %}
<div class="post">
<h2 class="title">{{post.title}}</h2>
<p class="meta"><span class="date">{{post.date}}</span><span class="posted">Posted by {{post.post_author}}</span></p>
<div style="clear: both;"> </div>
<div class="entry">
<p>
{{post.content}}
</p>
<p class="links">
Read More
Comments
</p>
</div>
</div>
{% endfor %}
</div>