Hi!
We are currently building the CMS for our customer, however, we came across an issue regarding using multi-languages in Hubl functions:
For the blog listing of a specific topic (or tag), we are using the Hubl function “blog_recent_tag_posts”. This function will fetch all the blog posts containing a specific tag that we are specifying by the field “tag”: blog_recent_tag_posts('default', module.tag , 200).
This seems to be working as it should on the primary language of the site, however, it does not work in a different language.
In our blog posts, we have the tag “Sustainability”. We want to show all the blog posts containing “Sustainability” on the Dutch version of the topic page. Therefore, we created a translation for this tag named “Dutch-sustainability”. This tag, however, does not fetch any data if we use the “blog_recent_tag_posts” function, while it should fetch the dutch blog posts. In addition, if a post contains the same tag for Dutch and English, only the English data can be used, meaning that the title, description etc. will not be shown in dutch.
While debugging this issue, I used the function “blog_tags” and noticed that only the tags were returned in the primary language.
Can you tell me what is the best way to fetch all blog posts containing a tag in a specific language? I first would suspect adding an additional parameter to the function containing language, but this does not seem to be the case.
Best regards,
Marc
``
Hi, @MSelles! Thanks for the interesting question. Let’s see if we can get the conversation rolling for you.
Hey @Stephanie-OG @alyssamwilie @jonchim, do y’all have any experience building out anything similar to what @MSelles is trying to accomplish?
Thank you! — Jaycee
Hi Marc!
I suspect that using 'default' for the blog parameter could be causing an issue. Add an extra “Blog” type field to your module and replace 'default' with module.blog like:
blog_recent_tag_posts(module.blog, module.tag , 200)
Then select the corresponding language blog wherever you’re using the module.
I ran a few quick tests using both default and selected blogs on both pages and blog listings and that seemed to do the trick.
Stephanie O’Gay Garcia
Freelance HubSpot CMS Developer
Website | Contact
Thank you, @Stephanie-OG
— Jaycee
Hi @Stephanie-OG ,
Thank you for looking into this issue for me!
I tried your solution, but I’m not sure if we can use this. Multiple languages exist in the same blog. For instance:
These blog posts are all linked to the same blog (that has the same blog id). Using a field to get the blog will still result in trying to fetch the data from 1 blog for all languages. Or am I maybe missing something?
Best regards,
Marc
Hey @MSelles - they’re language variations of the same blog, but when you add the “Blog” field to the module it’ll let you choose the different language variations. So I still think you need to choose the blog from the module if you’re using it on a page.
In my test, I have a language variation of a post under my Test Blog, the English post has a tag “test-tag” and the Spanish a tag “test-tag-es”:
Under settings, I’ve set the page title for the English variation to “Test Blog (English)” and the Spanish variation to “Test Blog (Spanish)”.
My test module has two fields (a Blog field blog and a Tag field tag) and the following code:
<h2>Function using "default" ()</h2>
{% set default_posts = blog_recent_tag_posts('default', module.tag , 200) %}
<ul>
{% for post in default_posts %}
<li>{{ post.name }}</li>
{% endfor %}
</ul>
<br>
<h2>Function selecting blog</h2>
{% set blog = blog_by_id(module.blog) %}
<h3>module.blog = {{ blog.html_title }} (ID: {{ module.blog }})</h3>
{% set blog_posts = blog_recent_tag_posts(module.blog, module.tag , 200) %}
<ul>
{% for post in blog_posts %}
<li>{{ post.name }}</li>
{% endfor %}
</ul>
When I test it on a page using the English variation of the blog, no posts with “test-tag-es” come up either under the “default” or the selected blog (because “Test Blog - Spanish” is not my default blog):
When I select “Test Blog - Spanish”, the post does appear under the function that uses module.blog:
So I think you need to specify the blog if you’re using it on a page.
Now, if you’re using the module on the Blog Listings or Blog Posts pages, the “default” should default to that specific language variation and it’ll work. It did in my tests.
Stephanie O’Gay Garcia
Freelance HubSpot CMS Developer
Website | Contact
I don’t know why, but I totally overlooked the “other language” blog in the field while filling the content.
@Stephanie-OG Thank you so much for the help!