How to get blog name from article object?

Solved

How to get blog name from article object?

cmegown
Shopify Partner
3 1 2

Hello everyone,

 

I'm creating a new "featured articles" section for a client where they can select one or more specific articles to showcase. The design is really quite simple but I'm having a hard time figuring out how to get the name of the associated/parent blog from the article object. It doesn't appear to be available in the documentation and my searching hasn't yielded any useful results.

 

There was one suggestion to grab the blog names from the article handles, but that won't work in this case as the blog names have special characters in them that are stripped out for URLs.

 

This information is surely available somewhere though, right? Pretty much everything else from an article is made available so the associated blog should be as well.

Accepted Solution (1)
cmegown
Shopify Partner
3 1 2

This is an accepted solution.

@Trudy it turns out that the blog object is implicitly available on the article template. I didn't really see this documented anywhere originally but realized it after Googling around for a while.

 

So, in other words, you don't really have to do anything special. Simply use {{ blog.title }}.

View solution in original post

Replies 6 (6)

ZestardTech
Shopify Partner
6096 1091 1465

Hello there,
please check this article
https://shopify.dev/api/liquid/objects/article

Want to modify or develop new app, Hire us.
If helpful then please Like and Accept Solution .
Email: support@zestard.com
Shopify Apps URL :- https://apps.shopify.com/partners/zestard-technologies
Custom Modifications Into Shopify Theme | Shopify Private App | SEO & Digital Marketing
cmegown
Shopify Partner
3 1 2

Uh, thanks? Do you care to expand on that comment? You didn't really answer anything. I clearly know what the article object is, and was looking for specific advice.

Trudy
Shopify Partner
11 1 4

Ok...this is kind of hacky, but I'm trying to do the same thing and you could use the template_suffix property.  Create an article template for each blog type (even if they're identical), then use the template_suffix to know which blog each article is from.

 

🙂

Looking to customize your theme? Don't hire a developer - instead check out Design Packs! https://apps.shopify.com/design-packs
cmegown
Shopify Partner
3 1 2

This is an accepted solution.

@Trudy it turns out that the blog object is implicitly available on the article template. I didn't really see this documented anywhere originally but realized it after Googling around for a while.

 

So, in other words, you don't really have to do anything special. Simply use {{ blog.title }}.

Trudy
Shopify Partner
11 1 4

Oh thanks!! That's really good to know!

Looking to customize your theme? Don't hire a developer - instead check out Design Packs! https://apps.shopify.com/design-packs

gerardm
Shopify Partner
4 0 4

I realize this post is a little older -- but in my case the client is able to choose articles to be displayed around the site and we needed to determine which blog it came from. So the global blog object did not work. Instead I wrote the following code to scrape the handle from the referenced article's url and get it from there.

 

{%liquid
assign split_1 = article.url | split: '/blogs/'
assign split_2 = split_1[1] | split: '/'
assign blog_handle = split_2[0] | strip
assign article_blog = blogs[blog_handle]
%}
 
Then you can reference article_blog to get whatever you may need like {{ article_blog.title }} or {{ article_blog.url }}