how to remove sonata project link from sonata admin pannel - sonata-admin

how can I remove sonata project link from sonata admin panel.
Your help is appreciated. Thanks

you need tyo override sonata-project/admin-bundle/Resources/views/standard_layout.html.twig
it is at line 247:
{% block side_bar_after_nav %}
<p class="text-center small" style="border-top: 1px solid #444444; padding-top: 10px">
{% block side_bar_after_nav_content %}
sonata project
{% endblock %}
</p>
{% endblock %}

Redefine sonata template:
sonata_admin:
templates:
layout: 'admin/app_layout.html.twig'
And in template redefine block side_bar_after_nav_content:
{% extends 'SonataAdminBundle::standard_layout.html.twig' %}
{% block side_bar_after_nav_content %}
{# Removes original sonata link #}
{% endblock %}

Related

In Wagtail streamfield template how to check if a field of a structblock inside a structblock is null?

I have a StructBlock like this :
class CardBlock(blocks.StructBlock):
header= blocks.StructBlock([
("text", blocks.CharBlock(required=False, help_text="Header text")),
("classes", blocks.CharBlock(required=False, help_text="Header css classes")),
],
template="streams/card_header_block.html")
image= ImageChooserBlock(required=False)
icon= blocks.CharBlock(required=False, help_text="fontawesome classes for an icon")
title= blocks.StructBlock([
("text", blocks.CharBlock(required=False, help_text="Title text")),
("classes", blocks.CharBlock(required=False, help_text="Title css classes")),
],
template="streams/card_title_block.html")
bodyHTML = blocks.RawHTMLBlock()
footer= blocks.StructBlock([
("text", blocks.CharBlock(required=False, help_text="Footer text")),
("classes", blocks.CharBlock(required=False, help_text="Footer css classes")),
],
template="streams/card_footer_block.html")
class Meta:
template = "streams/card_block.html"
icon = "placeholder"
label = "Card"
And a template like this:
{% load wagtailcore_tags %}
{% load wagtailimages_tags %}
{% image value.image fill-300x150 as img %}
<div class="card {% if value.classes %} {{value.classes}} {% endif %}">
{% if value.header.text is not Null %}
{% include_block value.header %}
{% endif %}
{% if value.image %}
<img src="{{ img.url }}" alt="{{ img.alt}}" class="card-img-top" />
{% endif %}
<div class="card-body">
{% if value.title %}
{% include_block value.title%}
{% endif %}
{% if value.subtitle %}
{% include_block value.subtitle%}
{% endif %}
<div class="card-text">{% include_block value.bodyHTML %}</div>
{% if value.link %}
{% include_block value.link%}
{% endif %}
</div>
{% if value.footer %}
{% include_block value.footer%}
{% endif%}
</div>
I am trying to check is a child block like Header has its value filled by the page editor or not. If not I do not show the HTML. But I am afraid the header div still shows up. Someting is wrong with the way I am putting the condition.
A blank CharBlock is equal to the empty string, which is not the same as null (and in any case, Python's null value is None, not Null). You can test this the same way that you've tested other empty values in your template: {% if value.header.text %}

Wagtail Show latest blog posts on Homepage through a streamfield

I have 3 mains sections in my site, homepage, blog index, and blog specific. I am using the streamfield function in wagtail to order various sections in the homepage. One of those sections is for the latest three blog posts.
I have done this for the blog index page, but can't grab the latest blog posts in the streamfield.
My model looks like this
class CaseStudiesIndex(Page):
def casestudies(pages):
casestudies = CaseStudyPage.objects.all().order_by('-first_published_at')
return casestudies
intro = RichTextField(blank=True)
content_panels = Page.content_panels + [
FieldPanel('intro', classname="full")
]
class LatestPosts(blocks.StructBlock):
static = blocks.StaticBlock(admin_text='Latest posts: no configuration needed.',)
def casestudies(pages):
casestudies = CaseStudyPage.objects.all().order_by('-first_published_at')[:3]
return casestudies
class Meta:
icon = 'doc-full'
label = 'Latest Posts'
template = 'blocks/_latestPosts.html'
class HomePage(Page):
blocksbody = StreamField([
('lead_banner', LeadBanner()),
('latest_posts', LatestPosts()),
('team', Team())
],null=True,blank=True)
content_panels = Page.content_panels + [
StreamFieldPanel('blocksbody'),
]
In my block folder I am calling the file fine and it renders the wrapper fine but I can't grab any of the data, I have tried a bunch of ways but nothing returns.
{% load wagtailcore_tags wagtailimages_tags %}
{% load static %}
<section>
<div class="wrapper__inner">
<ul>
{% for case in self.casestudies %}
{{case.title}}
{% endfor %}
{% for case in self.case_studies %}
{{case.title}}
{% endfor %}
{% for case in self.latest_posts %}
{{case.title}}
{% endfor %}
{% for case in page.casestudies %}
{{case.title}}
{% endfor %}
{% for case in page.case_studies %}
{{case.title}}
{% endfor %}
{% for case in page.latest_posts %}
{{case.title}}
{% endfor %}
</ul>
</div>
</section>
For the Blog Index page that does work I do the following.
{% extends "inner_base.html" %}
{% load wagtailcore_tags %}
{% block body_class %}template-case-studies{% endblock %}
{% block content %}
<section>
<div class="wrapper__inner">
<h1>{{self.title}}</h1>
<ul>
{% include "blocks/CaseStudiesLatestBlock.html" %}
</ul>
</div>
</section>
{% endblock %}
And the CaseStudiesLatestBlock.html which works fine looks like
{% load wagtailcore_tags wagtailimages_tags %}
{% load static %}
{% for case in self.casestudies %}
<li>
<strong>{{ case.title }}</strong>
</li>
{% endfor %}
Defining your own methods on a StructBlock won't work - the self (or value) variable you receive on the template is just a plain dict, not the StructBlock object itself. (This might seem counter-intuitive, but it's consistent with how blocks work in general: just as a CharBlock gives you a string value to work with and not a CharBlock instance, StructBlock gives you a dict rather than a StructBlock instance.)
Instead, you can define a get_context method (as documented here) to provide additional variables to the template:
class LatestPosts(blocks.StructBlock):
static = blocks.StaticBlock(admin_text='Latest posts: no configuration needed.',)
def get_context(self, value, parent_context=None):
context = super(LatestPosts, self).get_context(value, parent_context=parent_context)
context['casestudies'] = CaseStudyPage.objects.all().order_by('-first_published_at')[:3]
return context
You can then access the casestudies variable in the template, e.g. {% for case in casestudies %}.

Twig check if value is in array

I'm having trouble to check if a value is present in an array with Twig.
I want to hide a shipping method in a checkout if there's a certain product in the cart.
I can only use Twig code so I have to find a logic in that.
So let's say when product ID 1234 is in cart then I want to hide #certain_div
So what I have is this ->
{% if checkout %}
{% set array = theme.sku_shipping_rule | split(',') %}
// theme.sku_shipping_rule = a text string like 1234, 4321, 5478
{% if checkout.products %}
{% for product in checkout.products %}
{% if product.sku in array %}
<style>
#certain_div {
display: none;
}
</style>
{% endif %}
{% endfor %}
{% endif %}
{% endif %}
The problem I'm facing is that it seems my code always returns true. So even if the product.sku doens't match a value in the array it still hides #certain_div. I've tested that with placing {{ product.sku }} just before <style>.
What do I wrong?
Any help greatly appreciated!
UPDATE:
I've updated the question/code to show what's happening
{% if checkout %}
{% set skuToCheck = theme.sku_shipping_rule | split(',') %}
{% set skuInCart = [] %}
{% if checkout.quote.products %}
{% for product in checkout.quote.products %}
{% set skuInCart = skuInCart | merge([product.sku]) %}
{% endfor %}
{% endif %}
{% for myVar in skuInCart %}
{{ myVar }}<br/>
{% endfor %}
// this prints
PSYGA1 // where this sku should NOT match
FP32MA4
{% for myVar in skuToCheck %}
{{ myVar }}<br/>
// this prints
FP32LY4
FP32STR4
FP32MA4
{% if myVar in skuInCart %} // also tried with | keys filter
{{ myVar }} is found
{% endif %}
{% endfor %}
{% endif %}
So what I did is placing the sku's from the products which are in the cart in an array skuInCart. Next I want to check if myVar is present in the skuInCart array. If so print myVar is found.
What happens is that you should expect that it prints only the matching results. However it actually prints all values present skuInCart (using keys filter) or completely blank without using keys filter.
What you are doing in theory should work, have a look a this fiddle example to show you a working demonstration:
https://twigfiddle.com/yvpbac
Basically:
<div id="certain_div">
This should not show up
</div>
{% set searchForSku = "890" %}
{% set productSkuArrayString = "1234,4567,890" %}
{% set productSkuArray = productSkuArrayString|split(',') %}
{% if searchForSku in productSkuArray %}
<style>
#certain_div {
display: none;
}
</style>
{% endif %}
<!-- New Trial -->
<div id="certain_div">
This should show up
</div>
{% set searchForSku = "891" %}
{% set productSkuArrayString = "1234,4567,890" %}
{% set productSkuArray = productSkuArrayString|split(',') %}
{% if searchForSku in productSkuArray %}
<style>
#certain_div {
display: none;
}
</style>
{% endif %}
Will result in:
<div id="certain_div">
This should not show up
</div>
<style>
#certain_div {
display: none;
}
</style>
<!-- New Trial -->
<div id="certain_div">
This should show up
</div>
You can use iterable to check if a variable is an array or a traversable object:
{% if items is iterable %}
{# stuff #}
{% endif %}

Hyde copy code from content straight in to deploy

I'm using hyde (http://hyde.github.io) and everything is working great. Then I needed a page that is not static. I wrote it in php. Is there a way to have hyde just copy the content straight in to the deploy page from the content page?
{% extends "topbar.j2" %}
{% block container %}
{% block ignore %} *Hyde don't try to process just copy as is*
<h2> Search </h2>
<?php
... php code ...
echo "Stuff"
?>
{% endblock ignore %}
{% endblock container %}
So with some playing and deeper reading of the documentation.
The raw tag is for jinja syntax only (as shown)
{% raw %}
<ul>
{% for item in seq %}
<li>{{ item }}</li>
{% endfor %}
</ul>
{% endraw %}
Thought about turning off the markdown filter for the search page, but didn't want to create jinja page rules
Learned that one line of php does not seem to break the page.
<?php phpinfo(); ?>
Our solution
Move all php code back to its own file searcher.php
<?php
if(url is searcher.php redirect to search.php);
//code and stuff ... ;
echo "results";
?>
Keep the search.php page simple
{% extends "topbar.j2" %}
{% block container %}
<h2> Search </h2>
{% raw %}
<?php include_once("searcher.php"); ?>
{% endraw %}
{% endblock container %}

Jinja2 in google appengine extended template repeates base templete

Ok I have a base.html and I try to use that for my header menu and footer. In my other template I loop over items and display them on the page. My problem is the the other template is repeating my base.html like it's in the loop. I hope someone can show me the error in My ways.
Here is my base.html code:
<div class="menu">
<ul class="nav">
<li>Home</li>
<li>New Entry</li>
<li>Sign-up</li>
{% if user %}
<li>{{user.name}}</li>
<li>Log-Out</li>
{% else %}
<li>Log-In</li>
{% endif %}
</ul>
​
This is in the base.html also but didn't paste correctly.
<div id="content">
{% block content %}
{% endblock %}
</div>
And here is the sub template code:
{% extends "base.html" %}
{% block content %}
{% for p in posts %}
{{ p.render() | safe }}
<br><br>
{% endfor %}
<div>
{{text}}
</div>
{% endblock %}
Please help
Edit:
edit2: removed link and found my problem I was calling the wrong html file in render()
Be kind Newbie here
Looks ok. Are you sure you don't have a loop in the python code that renders the template?

Resources