I am trying to get my instance internatinalized and I am giong crazy a little bit.
Trying the whole day to solve a simple problem and read a lot, but can’t seem to find a solution.
I am using the Edition theme and am in the related-posts.hbs
I have multiple posts. Each tagged with a language hashtag (#en, #de, #fr, …)
{{#has tag=“#en”}} works in the {{post}} context.
What I try to achieve are two things:
- give the text “You might also like…” in the specific language
- filter the related posts by the given internal language tag additionally, so only Posts in the specific current post language are shown.
The original code is:
{{#get "posts" limit="5" filter="tags:[{{post.tags}}]+id:-{{post.id}}" as |related|}}
{{#if related}}
<section class="related-wrapper gh-canvas">
<h3 class="related-title">You might also like...</h3>
<div class="post-feed related-feed">
{{#foreach posts}}
{{> "loop"}}
{{/foreach}}
</div>
</section>
{{/if}}
{{/get}}
What I tried is something like:
{{#foreach post.tags}}
{{#match name "hash-en"}}
{{#set "lang_tag"}}hash-en{{/set}}
{{/match}}
{{#match name "hash-de"}}
{{#set "lang_tag"}}hash-de{{/set}}
{{/match}}
{{#match name "hash-fr"}}
{{#set "lang_tag"}}hash-fr{{/set}}
{{/match}}
{{#match name "hash-es"}}
{{#set "lang_tag"}}hash-es{{/set}}
{{/match}}
{{#match name "hash-it"}}
{{#set "lang_tag"}}hash-it{{/set}}
{{/match}}
{{#match name "hash-nl"}}
{{#set "lang_tag"}}hash-nl{{/set}}
{{/match}}
{{#match name "hash-pt"}}
{{#set "lang_tag"}}hash-pt{{/set}}
{{/match}}
{{#match name "hash-pl"}}
{{#set "lang_tag"}}hash-pl{{/set}}
{{/match}}
{{#match name "hash-ru"}}
{{#set "lang_tag"}}hash-ru{{/set}}
{{/match}}
{{#match name "hash-ja"}}
{{#set "lang_tag"}}hash-ja{{/set}}
{{/match}}
{{#match name "hash-zh"}}
{{#set "lang_tag"}}hash-zh{{/set}}
{{/match}}
{{/foreach}}
{{#get "posts" limit="5" filter="tags:{{@lang_tag}}+tags:[{{post.tags}}]+id:-{{post.id}}" as |related|}}
{{#if related}}
<section class="related-wrapper gh-canvas">
{{#match @lang_tag "hash-en"}}
<h3 class="related-title">You might also like...</h3>
{{/match}}
{{#match @lang_tag "hash-de"}}
<h3 class="related-title">Das könnte dich auch interessieren...</h3>
{{/match}}
{{#match @lang_tag "hash-fr"}}
<h3 class="related-title">Vous pourriez aussi aimer...</h3>
{{/match}}
{{#match @lang_tag "hash-es"}}
<h3 class="related-title">También te puede gustar...</h3>
{{/match}}
{{#match @lang_tag "hash-it"}}
<h3 class="related-title">Potrebbe piacerti anche...</h3>
{{/match}}
{{#match @lang_tag "hash-nl"}}
<h3 class="related-title">Je zou dit ook leuk kunnen vinden...</h3>
{{/match}}
{{#match @lang_tag "hash-pt"}}
<h3 class="related-title">Você também pode gostar...</h3>
{{/match}}
{{#match @lang_tag "hash-pl"}}
<h3 class="related-title">Możesz również polubić...</h3>
{{/match}}
{{#match @lang_tag "hash-ru"}}
<h3 class="related-title">Вам также может понравиться...</h3>
{{/match}}
{{#match @lang_tag "hash-ja"}}
<h3 class="related-title">あなたも好きかもしれません...</h3>
{{/match}}
{{#match @lang_tag "hash-zh"}}
<h3 class="related-title">你可能还喜欢...</h3>
{{/match}}
<div class="post-feed related-feed">
{{#foreach related}}
{{> "loop"}}
{{/foreach}}
</div>
</section>
{{/if}}
{{/get}}
But that did not work, the element just stays empty.
I had versions with #has that just outputed the related-title like that which worked:
{{#post}}
{{else has tag="#en"}}
<h3 class="related-title">You might also like...</h3>
{{else has tag="#fr"}}
<h3 class="related-title">Vous pourriez aussi aimer...</h3>
{{else has tag="#es"}}
<h3 class="related-title">También te podría interesar...</h3>
{{else has tag="#it"}}
<h3 class="related-title">Potrebbe interessarti anche...</h3>
{{else}}
<h3 class="related-title">Das könnte dich auch interessieren...</h3>
{{/has}}
{{/post}}
But when I then try to insert the filter block into the has blocks, they just stay empty:
{{#get "posts" limit="5" filter="tags:hash-de+tags:[{{post.tags}}]+id:-{{post.id}}" as |related|}}
{{#if related}}
I think I mess around with the contexts and I just can’t get the correct way.
I could also live with a realy impropper solution like the following, if it would just work, but my brain got wasted already:
{{#post}}
{{#has tag="#de"}}
{{#get "posts" limit="5" filter="tags:hash-de+tags:[{{post.tags}}]+id:-{{post.id}}" as |related|}}
{{#if related}}
<section class="related-wrapper gh-canvas">
<h3 class="related-title">Das könnte dich auch interessieren...</h3>
<div class="post-feed related-feed">
{{#foreach related}}
{{> "loop"}}
{{/foreach}}
</div>
</section>
{{/if}}
{{/get}}
{{else has tag="#en"}}
{{#get "posts" limit="5" filter="tags:hash-en+tags:[{{post.tags}}]+id:-{{post.id}}" as |related|}}
{{#if related}}
<section class="related-wrapper gh-canvas">
<h3 class="related-title">You might also like...</h3>
<div class="post-feed related-feed">
{{#foreach related}}
{{> "loop"}}
{{/foreach}}
</div>
</section>
{{/if}}
{{/get}}
{{/has}}
{{/post}}
Is there a way to find an internal post tag matching something of a list, store that in a kind of variable and use it for match afterwards?
Something like in my first try?
Btw. I also tried to move the language hashtag to the first element of the Tags of the post and tried different combinations of
tags:[{{post.primary_tag}}]
tags:[{{post.primary_tag.slug}}]
tag:{{post.primary_tag}}
primary_tag:{{post.primary_tag}}
…
in the filter. None of them worked, the list always kept empty.
How you would solve that?