I have a blog created on Github Pages using Jekyll Now
The default Index.html looks like this
---
layout: default
---
<div class="posts">
{% for post in site.posts %}
<article class="post">
<h2>{{ post.title }}</h2>
<div class="entry">
{{ post.excerpt }}
</div>
Read More
</article>
{% endfor %}
</div>
This creates a landing page where the titles of all the posts you have made in the _posts directory are displayed with a link.
Looking at the {% for ... %} & {% endfor %} & the final static HTML, it seems as if when building the page, the for tag is actually iterated & the final HTML contains a list of actual titles.
I want to change this so that not all posts are listed. I do not want to list any post whose title contains the string "BEINGWRITTEN"
I tried stuff like
{% for post in site.posts %}
{% if (post.title.indexOf('BEINGWRITTEN') == -1) %}
<article class="post">
...
</article>
{% endif %}
{% endfor %}
Also tried with includes instead of indexOf, that also doesn't work. Both cases, I don't see any posts linked at all on the landing page.
How do I do this?
I did this by adding a category in the front matter of the page I don't want included.
i.e.
category: noshow
Then changed the index.html to
{% for post in site.posts %}
{% unless post.category == "noshow" %}
.....
{%endunless}
{%endfor}
Related
Ok, so I am making a project, where you can make new blogposts and edit existing blogposts in Python with Django, but when I want to make a new post on my website, the "submit" button in new_post.html does nothing when I press it. I fill in the 'title' field and I fill in the 'text' field from the ModelForm "BlogPostForm" and press the button. In the terminal there's no POST or GET request. I just don't know why?
I'm using Python 3.6.4 and Django 2.1, installed in a virtual environment created by the "venv" module.
base.html:
<p>
Blogs
</p>
{% block content %}{% endblock content %}
index.html:
{% extends "blogs/base.html" %}
{% block content %}
<p>All posts:</p>
<ul>
{% for blog in blogs %}
<li>
{{ blog }}
<p>{{ blog.date_added|date:'M D, Y H:i' }}</p>
<p>{{ blog.text|linebreaks }}</p>
<p>-------------------------------------<p>
</li>
{% empty %}
<li>No posts are posted yet.</li>
<p>
Add new post
</p>
{% endfor %}
</ul>
<p>
Add new post
</p>
{% endblock content %}
new_post.html:
{% extends "blogs/base.html" %}
{% block content %}
<p>Make a new post:</p>
<post action="{% url 'blogs:new_post' %}" method='post'>
{% csrf_token %}
{{ post.as_p }}
<button name='submit'>Add Post</button>
</post>
{% endblock content %}
Thanks in advance!
There is no <post> tag in HTML. To post a data you need to use a <form> tag. Everything else is correct.
I am at my wits-end and feel I am missing something simple but I've looked at it over and over and can't figure it out.
I have a simple person_index_page that I want to show the child person_page objects, but no matter what I try...nothing. I have several sites with a similar setup and they work. Can you please look at my code below and see if you notice something I am missing? Thank you.
home_tags.py
# Person feed for home page and staff page
#register.inclusion_tag(
'home/tags/person_listing_homepage.html',
takes_context=True
)
def person_listing_homepage(context, count=3):
people = PersonPage.objects.live().order_by('?')
return {
'people': people[:count].select_related('feed_image'),
'request': context['request'],
}
person_index_page.html
{% extends 'base.html' %}
{% load wagtailcore_tags wagtailimages_tags home_tags %}
{% block content %}
...
{% include "home/tags/person_listing_homepage.html" %}
...
{% endblock %}
person_listing_homepage.html probably should name this at some point
{% for person in people %}
{% include "home/includes/person_list_item.html" %}
{% endfor %}
person_list_item.html
{% load wagtailcore_tags wagtailimages_tags %}
{# Individual person item in a list - used on people index and home page #}
<a class="list-group-item" href="{% pageurl person %}">
<div class="media">
{% if person.feed_image %}
<div class="media-left">
{% image person.feed_image width-200 as img %} <img class="media-object" src="{{ img.url }}"/>
</div>
{% endif %}
<div class="media-body">
<h4 class="media-heading">{{ person.first_name }} {{ person.last_name }}</h4>
{% if person.search_description %}
<p>{{ person.search_description }}</p>
{% endif %}
</div>
</div>
</a>
This is more of a "how to debug" question than a Wagtail one. Rather than just giving you the answer directly, here's the process I would take:
You say that adding print(people) inside the person_listing_homepage function doesn't display anything. So, your next question should be: "is this function being run at all?" Change the print statement to print("GOT HERE"). You'll find that this doesn't display anything either - which tells you that the function is not being run.
The next step would be to add some debugging output around the place where the function should be called from - if that doesn't get displayed either, you know that code isn't being run either, and you'd have to keep going up a level until you find something that is being run. So let's look for that place...
And this is where you find the problem. You never call the person_listing_homepage function anywhere in your code. You include the person_listing_homepage.html template, but that's not the same thing. person_index_page.html should become:
{% extends 'base.html' %}
{% load wagtailcore_tags wagtailimages_tags home_tags %}
{% block content %}
...
{% person_listing_homepage %}
...
{% endblock %}
I'm making a site for which I use cmsplugin-articles 0.2.2. That means that there's a page on the site (News) which has nested child pages which are the news. In the parent page you view a list of news teasers. (This is the way the plugin works.)
Looking into the template of the article teaser that the plugin provides:
{% load article_tags i18n %}
<div class="article">
{% block teaser_head %}
<time datetime="{{ article|published_at|date:"Y-m-d" }}">{{ article|published_at|date:"d.m.Y" }}</time>
<h2>{{ article|teaser_title }}</h2>
{% endblock %}
{% block teaser_body %}
{% with article|teaser_image as image %}
{% if image %}
<img src="{{ image.url }}" />
{% endif %}
{% endwith %}
<p>
{% teaser_text article %}
{% trans "More" %}
</p>
{% endblock %}
</div>
you can see the templatetag {% teaser_text article %} that should show some kind of text in the news teaser when rendering the News page.
I've published some news with some text for each one and when I go to the News page I can see the teasers list ok, but not any text, only the title, date, paginator and the "more" link, that proceed from other templatetags different than {% teaser_text %}.
Now the question is: does anybody knows how I can show each news text into each teaser (better an extract) when rendering the News page?
I was adding pagination to my website tonight and I ran into issues where now I have broke my whole site.
I am using the standard Jekyll directory structure for the files. For my website, I want the index page to be about me, then you click the /blog page to view my blog. So I have index.md be by main page. Then I have a page blog.html be the blog page. I used to use {% for post in site.posts limit: 10 %} which worked and switched to {% for post in paginator.posts %} based on how the latest documentation recommended the loop and it broke. In my _config.yml file I have:
paginate: 10
paginate_path: "blog/page:num"
permalink: /blog/:year/:month/:day/:title.html
I want the paging to be /blog/page2.html. I am unsure what I have configured wrong. Here is my entire blog.html page:
---
title: Blog
layout: default
permalink: /blog/index.html
---
{% for post in paginator.posts %}
<div class="row">
<div class="col-lg-12">
{% if post.layout contains "link" %}
<h4><i class="icon-link"></i> {{post.title}}</h4>
{% else %}
<h4>{{post.title}}</h4>
{% endif %}
<small>{{post.date | date: "%m/%d/%Y"}}</small>
<div class="post-content-truncate">
{% if post.content contains "<!-- more -->" %}
{{ post.content | split:"<!-- more -->" | first % }}
Read full article...
{% else %}
{{ post.content }}
{% endif %}
</div>
</div>
</div>
{% endfor %}
{% if paginator.total_pages > 1 %}
<div class="row">
<div class="col-lg-12">
<ul class="pagination">
{% if paginator.previous_page %}
<li>« Prev</li>
{% else %}
<span>« Prev</span>
{% endif %}
{% for page in (1..paginator.total_pages) %}
{% if page == paginator.page %}
<li><em>{{ page }}</em></li>
{% elsif page == 1 %}
<li>{{ page }}</li>
{% else %}
<li>{{ page }}</li>
{% endif %}
{% endfor %}
{% if paginator.next_page %}
<li>Next »</li>
{% else %}
<li><span>Next »</span></li>
{% endif %}
</ul>
</div>
</div>
{% endif %}
Any ideas of where I am going wrong?
The problem was actually two problems:
I was using an older version of Jekyll. Once I upgraded to the latest it was almost working.
I had to put my /blog.html file into /blog/index.html
Once I did those two steps it worked.
I am using django-pagination to paginate the a list of objects in my temlate. I have installed the app, added it in my project and added pagination.middleware.PaginationMiddleware in my settings.py file. But when I try to use it in my template the object_list is not being paginated. Here is my template code
{% extends "base.html" %}
{% load pagination_tags %}
{% autopaginate Questions %}
{% block title %}
Questions
{% endblock %}
{% block content %}
<div id="contentDiv">
{% for question in Questions %}
<div style="padding:5px 20px 5px 30px;">
<p class='question'><span id='style2'>Q
</span> {{ question.questiontext|safe }}
<span style= 'float:right;'><span style='font-size:12px; color:#099;'><a href="/question/type={{question.type}}"
style='font-size:12px; color:#099;'>{{question.type}}</a></span> <span style='color:#99C; font-size:12px;'>Level: </span><span style='color:#099;font-size:12px;'>{{question.level}}</a></span></span>
</p>
<h2 class='trigger1' ><a href='#'>Answer</a></h2>
<div class='toggle_container' >
<div class='block' style='background-color:#fff; '>
<p class='ans'> {{ question.answer|safe }} </p>
</div>
</div>
</div>
{% endfor %}
<div class="pagination" style="width:1000px; margin:auto; margin-bottom:20px;">
{% paginate %}
</div>
</div>
{% endblock %}
The list of objects is in the context_variable called Questions. Am I doing something wrong?
After a very long time I have been able to find out the error I was having with django-pagination. I had the canonical base template which I was extending on all pages.
In the documentation it is written that we require to put {% paginate %} after {% autopaginate object_list %} but no where it was written about the placement of {% autopaginate object_list %} itself.
I had title and body blocks in my template, and I was putting {% autopaginate object_list %} just below the {% extends "base.html" %} and as a result it was not working. I found that I had to put this statement inside the body block and now it is working absolutely fine.
Can you see the content of your pagination div if you write "Hello, I want a burger" or anything else in there?
Are you sure you have enough Questions to paginate? You could try something like:
{% autopaginate Questions 2 %}
to make sure that you'll be paginating at 2 questions/page.
Solved as Sachin told above:
I just moved {% load pagination_tags %}{% autopaginate list_objs 10 %}
inside {% block content %} statement (previously it was outside of it, so pagination was invisible. If no errors, but now pages - try to play with it (moving pagination block).