Display blogs posts in custom html homepage

Hello community. I have integrated a custom html5 bootstrap template to my Frappe and it’s going well. I’m stuck at displaying Blog Posts like in the default homepage that comes with Frappe and ERPNext. I have copied the html code from erpnext/erpnext/templates/includes/home.html:

<section class="container my-5">
		<h3>{{ _('Publications') }}</h3>

		<div class="row">
			{% for blog in blogs %}
			<div class="col-md-4 mb-4">
				<div class="card h-100">
					<div class="card-body">
						<h5 class="card-title">{{ blog.title }}</h5>
						<p class="card-subtitle mb-2 text-muted">{{ _('By {0}').format(blog.blogger) }}</p>
						<p class="card-text">{{ blog.blog_intro }}</p>
					</div>
					<div class="card-body flex-grow-0">
						<a href="{{ blog.route }}" class="card-link">{{ _('Read blog') }}</a>
					</div>
				</div>
			</div>
			{% endfor %}
		</div>
	</section>

as well as from the home.py:

import frappe

def get_context(context):

	context.blogs = frappe.get_all('Blog Post',
		fields=['title', 'blogger', 'blog_intro', 'route'],
		filters={
			'published': 1
		},
		order_by='modified desc',
		limit=3
	)

Somehow it does not show on my custom template, what am I missing? :slight_smile:

In your python file add these below lines to get_context and make blogs as local variable.

out = {
	"blogs":  blogs
}

return out
1 Like

So, I’ve tried what you’ve described in multiple ways but I’m still not getting the blogs in my front-end. I appreciate it though :slight_smile: if you do get the time, would you mind taking another look?

You got to debug this by adding console logs to check if your blogs is populated with content on the browser console.