I'm starting a Wagtail site. In the admin section, I went to Settings >> Sites >> localhost, and set "Site name" to "My first Wagtail site."
How do I display the site title in templates using Django code?
The tag to use is:
{{ request.site.site_name }}
Old version
<h1>Welcome to the {{ request.site.site_name }} website!</h1>
new version
{% load wagtailcore_tags %}
{% wagtail_site as current_site %}
<h1>Welcome to the {{ current_site.site_name }} website!</h1>
Reference: https://docs.wagtail.io/en/stable/releases/2.9.html#upgrade-considerations
in wagtail 4.1,use {{page.get_site}} in template.
Related
I am trying to build a blog website using hugo. Everything is going all right on my site except for showing the blog list on the homepage. I want to show all blogs on the homepage but my theme is not doing it automatically. I am using Mediumish theme. In this theme, if I add any content in the config.toml it will show in the homepage. There are some text contents on the homepage. Now, I want to replace them with blog list. How Can I do that?
Thanks in advance!
N.B: currently the blogs are showing in the cold-email-bootcamp slug - https://splendid-pavlova-fbf620.netlify.app/cold-email-bootcamp/
Code Link: https://github.com/shawon111/hugo-sharable
live website link: https://splendid-pavlova-fbf620.netlify.app/
No clue how the theme was set-up, but if you want to show all content on your homepage - ALL CONTENT:, in index.html:
{{ range .Site.Pages }}
{{ .Content }}
{{ end }}
You'll probably want to:
{{ range .Site.Pages }}
<article>
<h4>{{ .Title }}</h4>
<p>{{ .Summary }}</p>
Read more
</article>
{{ end }}
I have extended sonata edit page with this:
{% extends '#SonataAdmin/CRUD/base_edit.html.twig' %}
{% block javascripts %}
{{ parent() }}
{{ encore_entry_script_tags('select2', null, 'admin') }}
{% endblock %}
But now when I click + button nera "Product option group codes" , it adds 2 rows.
If I remove
{{ encore_entry_script_tags('select2', null, 'admin') }}
then it works ok - adds just one row on + click.
I have commented all code in selec2.js file, to make sure it is not causing something but still nothing changes.
If I remove
parent()
Then "Product option group codes" js stops working.
How to debug? Where could be the problem?
Noticed that this js was not by sonata, but in our script. And when adding
{{ encore_entry_script_tags('select2', null, 'admin') }}
it calls document ready in another JS 2nd time, which setups + sign listener. So 2 listeners are set up.
To avoid this, instead of encore function, using script tag solved the problem. Also changed file name which I include.
{% extends '#SonataAdmin/CRUD/base_edit.html.twig' %}
{% block javascripts %}
{{ parent() }}
<script src="{{ asset('build/admin/admin-state-disaster-scenario.js', 'admin') }}"></script>
{% endblock %}
I am a true beginner in Wagtail. How do I generate a list of pages in the sections for a sidemenu in Wagtail?
I have the following site structure, as an example:
home/
fruits/
apples/
oranges/
grapes/
vegetables/
kale/
spinach/
cabbage/
home is of HomePage type using home_page.html template , and all the subpages are of ContentPage type using content_page.html template.
I want to make a side menu for all the content pages, listing all the pages in their groups. For example, this list:
Fruits
Apples
Oranges
Grapes
should be the sidemenu for the pages fruits, apple, oranges, and grapes.
page.get_children in the template only lists out if the page has children, so, in this case just fruits and vegetables.
How would I go about making that sidemenu?
The examples in Wagtail's documentation seem to imply that I can't have just a generic content type like ContentPage to have the sort of listing that I want, is that true?
Thanks a bunch!
welcome to Wagtail!
As with most things in web development, there are a few ways you can do this. The simplest to understand when you're just starting is to do this all through the template. So in your home_page.html you could have:
{% for parent in page.get_children %}
Page title: {{ parent.title }} <br />
{% if parent.get_children.count %}
{% for child in parent.get_children %}
- Child page title: {{ child.title }}<br/>
{% endfor %}
{% endif %}
{% endfor %}
What this does is:
Loops through the child pages of HomePage (labeled as parent in this loop) and prints Page title: {title_here}
Then it'll check for child pages of each parent loop iteration and print - Child page title: {child_title}
There's a gotcha here though. This will only work on the home_page.html template. Once you go to /fruits/ it'll try to perform the same logic, but this time it'll think Fruits is the new HomePage
There are 2 options you can take from here.
You can add custom context to every page to make sure you're always passing in the HomePage and loop through that. This is the simplest method and I'll show you the code below. Or,
You can create a Menu system using a Django Model and registering the Menu class as a Wagtail Snippet. I have a video with all the source code available if you want to take a deeper dive into Wagtail (https://www.youtube.com/watch?v=Y8a9ROUUJXU)
To add HomePage to every ContentPage you can add it to the context of every page, like so:
class ContentPage(Page):
# Fields here
def get_context(self, request, *args, **kwargs):
"""Adding HomePage to your page context."""
context = super().get_context(request, *args, **kwargs)
context["home_page"] = HomePage.objects.first()
return context
And in your templates you'd write:
{% for child_page in home_page.get_children %}
Page title: {{ child_page.title }} <br />
{% if child_page.get_children.count %}
{% for grandchild_page in child_page.get_children %}
- Child page title: {{ grandchild_page.title }}<br/>
{% endfor %}
{% endif %}
{% endfor %}
Edit: If you're on a grandchild page, like /fruits/apples/ and want to display the parent page title, and all the sibling pages (ie. /fruits/oranges/ and /fruits/grapes/) you can loop through the sibling pages. Something like this should work:
<!-- On `/fruits/` this will be the Home Page title. On `/fruits/apples/` this will be the Fruits page title. -->
<h2>{{ self.get_parent.title }}<h2>
{% for sibling in self.get_siblings %}
{{ sibling.title }}
{% endfor %}
So this awesome Wagtail/Django framework is nice!
I like it allot.
Still getting used to but seems straight forward,
What I do not understand tho is how can I access default page models and render them in the templates?
So Wagtail has this models that you make based on their Page class.
class SomeClass(Page):
"""
Some text
"""
intro = models.CharField(max_length=255, blank=True)
body_small = models.CharField(max_length=255, blank=True)
All good and well.
Now my page template looks like this
{% extends "base.html" %}
{% load wagtailcore_tags %}
{% block base_content %}
{{ page.intro }}
{{ page.body_small }}
{% endblock %}
Now I want to add the settings model items like Published Date.
Those are default from Wagtail, see:
What page model do I need to use?
{{ page.published_date }} //Does not work
Any suggestions?
The fields in the Settings tab are available as {{ page.go_live_at }} and {{ page.expire_at }}. However, these are only used for scheduled publishing so may not be a particularly relevant thing to output on the page - {{ page.first_published_at }} and {{ page.last_published_at }} are probably more useful. See http://docs.wagtail.io/en/stable/reference/pages/model_reference.html for more.
I am trying to implement search in jekyll using angularjs but not able to display . can anyone suggest me how can i plan for search in jekyll site using angularjs.
on submit of search text need to shoe list of blog posts with search text. how can i form search.json and how can add filter to load page faster .
another problem is can we use same index.html which is for blog
{% for post in paginator.posts %}
<div class="entry">
{% include blog/post_header.html post=post %}
<div>
{{ post.excerpt | markdownify }}
<p>Read post <i class="fa fa-arrow-right"></i></p>
</div>
</div>
{% endfor %}
to again display filtered blogs ?