Hello!
I am trying to implement related posts under blog post, but I have a problem with overwriting one of the variable.
Here is the piece of code:
{% set related_posts = blog_recent_topic_posts('default', topic.slug, 3 ) %}
{% set posts_count = 0 %}
{% if related_posts|length < 2 %}
{% for topic_new in content.topic_list %}
{% if topic.slug != topic_new.slug %}
{% set new_posts = blog_recent_topic_posts('default', topic_new.slug, 3 ) %}
{% set related_posts = related_posts ~ new_posts %}
<script>console.log("Posts in a loop: {{ related_posts }}");</script>
{% endif %}
{% endfor %}
{% else }
{% set related_posts = blog_recent_topic_posts('default', topic.slug, 3 ) %}
{% endif %}
<script>console.log("Posts: {{ related_posts }}");</script>
I cannot change variable “related_posts”. I am trying to sign a new value inside the loop (there it works, console log shows new values) but in the end last console log always shows value from the 1st line of code.
Do you know what is a problem here?
Thanks!