My client has had someone else to develop their theme and now wants me to set up a bio page for authors.
Their blog listing page looks like this:
Spoiler
{% set body_class = “blog-listing-page” %}
{% extends “./../layouts/base.html” %}
{% block body %}
{% module “article-listing”
path=“./../modules/article-listing”,
label=“Article listing”,
no_wrapper=true %}
{% endblock body %}
So they call a module and extend a layout. This looks super clean and fun, but I can’t declare a {% if blog_author %} statement, God knows why. I get syntax error, regardless where I put the if statement. I have tried in the listing template (where I have used to declare it), I have tried in the module and in the layout. None of them wants to accept the if blog_author statement.
Is there any way to work around this?
Hi @sylvio-otercar
Can you share how you are trying to use the {% if blog_author %} and what exact error you are getting?
This by itself should not be causing errors in templates or modules:
{% if blog_author %}
<!-- your code here -->
{% endif %}
Aha! I was ending it with else, not endif.
It now doesn’t give the error code, but the code isn’t working as it should. Nothing happens. Trying for instance this:
Spoiler
{% if blog_author %}
<p>
HELLO WORLD
</p>
{% endif %}
{% set body_class = “blog-listing-page” %}
{% extends “./../layouts/base.html” %}
{% block body %}
{% module “article-listing”
path=“./../modules/article-listing”,
label=“Article listing”,
no_wrapper=true %}
{% endblock body %}
But nothing happens in the page. I get the header of the webpage (as it should), but istead I get a text saying
“BlogListingPage 136064455185 (clientName) blog | (authorName)”
This is both interesting and higly annoying haha
This ultimately depends on what you are trying to build.
Firstly, the you may already know, but just in case, the blog author page is created automatically by HubSpot and can be accessed at:
yourwebsite.com/blog/author/author-name
(assuming your blog slug is “blog” and “author-name” should be replaced with the actual slug of the author that exists in your blog)
So if your goal is to add a section with the author bio to that automatically generated author page, your code should look something like this:
{% set body_class = "blog-listing-page" %}
{% extends "./../layouts/base.html" %}
{% block body %}
{% if blog_author %}
<p>
HELLO, THIS IS {{ blog_author.display_name }}
</p>
{% endif %}
{% module "article-listing"
path="./../modules/article-listing",
label="Article listing",
no_wrapper=true %}
{% endblock body %}
The {% if blog_author %} should be placed inside the {% block body %}
My brother in Christ. Indeed I was blind, but now I see. Thank you!
I realised firstly, as you mention, that I wasn’t editing the body of the page. Additionally, I was struggling (HARD) with syntax problem because I was using else, but never closing the if statement. Looked too much into the code and at some point stopped seeing the obvious.
Problem solved, thank you very, very much!
If I’m understanding, you’d want to do your conditionals within that module, which is where the logic for blog_author would presumably be.