How to use a javascript file variable to the hubspot blog listing template.

I want a variable in my blog listing template such that on clicking a button that variable is changed and according to the value of variable the blog are displayed , according to different categories.

1 First method that I tried

{% set obj1 = {val : “all_post”} %} // declaredd this as a variable in hubspot template

<button class=“btn active” onclick = " {%do obj1.update({val: “Featured” })%}"> Company culture</button>

in this method the value is updated as soon as the page is opened and nothing happens on clicking a button
2. Second method I want

$.Properties = ‘all_post’;//variable declared in seperate file

//then using jquery to update the variable

$(“#button-one”).click(function () {
Properties= “abc”
location.reload(true)
});

the problem with this is that I cannot use this variable i.e Properties inside the hubspot template.

Hey @ashadabbas15

Thank you for the information provided.I’ll tag a few experts that can share their experience with you.

Hey @eduardoavargas @piersg @narmstrong any thoughts you would like to share with @ashadabbas15?

Thanks

Sharon

Hey I found a temp method of doing that using CSS.

But now stuck in another problem

{% set Employee_Engagement = blog_recent_tag_posts(‘default’, ‘employee engagement’ , 100) %}

{% for content in Employee_Engagement %}
this is returnng nothing, everything empty here,
but if I am using

{% for content in contents %}
{% if ‘employee engagement’ in content.topic_list|map(‘name’)%}
it is working , but I dont want to use this method cause we have set the limit of 9 post per page and it return max of 9 post
but using the first method we can set a limit of how much post we want manually in hubl

Hi @ashadabbas15

I don’t think blog tags can be have whitespace in them so I would check what the tag_slug is exactly. Chances are it’s probably “employee-engagment”. In which case:

{% set Employee_Engagement = blog_recent_tag_posts('default', 'employee-engagement' , 100) %}
{% for content in Employee_Engagement %} // do things{% endfor %}

Re: your original post @ashadabbas15 I think what you’re trying to do is have a button to show the featured blog post, correct?

Firstly, HubL is executed server-side (before the page is presented to the browser), and so you can’t use HubL functions or update HubL variables on the client-side (from the browser).

To have a button that shows you a specific blog category, in this example “Featured”, when clicked it would look like this:

<button class="btn active" href="{{ blog_tag_url('default', 'featured')}}">Featured blogs</button>

This will take the user to that blog tag’s listing page. However, it’s not entirely clear what you want so if you could give more detail, I could be more specific/helpful.