<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to use javascript variables in hubspot in CMS Development</title>
    <link>https://community.hubspot.com/t5/CMS-Development/How-to-use-javascript-variables-in-hubspot/m-p/625607#M28554</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/331743"&gt;@JVallejo7&lt;/a&gt;,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Building off of&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/101258"&gt;@Teun&lt;/a&gt;'s suggestion of using the content search API, I put something quick together that I think achieves the basics of what you're looking for:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{% set my_tags = blog_tags('default', 250) %}


&amp;lt;select onchange="searchResults()" name="blog_tags" id="blog_tags"&amp;gt;
{% for item in my_tags %}
  &amp;lt;option value="{{item.name}}"&amp;gt;{{ item.name }}&amp;lt;/option&amp;gt;
{% endfor %}
&amp;lt;/select&amp;gt;

&amp;lt;div id="search-results"&amp;gt;&amp;lt;/div&amp;gt;

{%require_js %}
&amp;lt;script&amp;gt;
function searchResults() {
  var selectedTag =  document.getElementById('blog_tags').value;

  $.ajax({
    url: 'https://api.hubapi.com/contentsearch/v2/search?portalId={{ hub_id }}&amp;amp;property=tag&amp;amp;term='+selectedTag,
    type: 'GET',
    dataType: 'text',
    success: function(data) {
      var json_result = JSON.parse(data);
          
    let text = "";
const posts = json_result.results;
posts.forEach(printPosts);
    
    document.getElementById('search-results').innerHTML = text;
    
    function printPosts(item, index) {
  text += index + ": " + item['title'] + "&amp;lt;br&amp;gt;"; 
}
    }
  });
}
searchResults();
  &amp;lt;/script&amp;gt;
{%end_require_js %}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can further shape your results using the parameters here:&amp;nbsp;&lt;A href="https://legacydocs.hubspot.com/docs/methods/content/search-for-content" target="_blank" rel="noopener"&gt;https://legacydocs.hubspot.com/docs/methods/content/search-for-content&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 02 May 2022 18:36:22 GMT</pubDate>
    <dc:creator>BarryGrennan</dc:creator>
    <dc:date>2022-05-02T18:36:22Z</dc:date>
    <item>
      <title>How to use javascript variables in hubspot</title>
      <link>https://community.hubspot.com/t5/CMS-Development/How-to-use-javascript-variables-in-hubspot/m-p/623973#M28516</link>
      <description>&lt;P&gt;I'm pretty sure this topic has already been discussed elsewhere, but I can't quite find the information.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to do the typical search filter so that the server shows to the client the blog data based on the tags that the client has selected. For example:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;select name="cars" id="cars"&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;option value="volvo"&amp;gt;Volvo&amp;lt;/option&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;option value="saab"&amp;gt;Saab&amp;lt;/option&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;lt;/select&amp;gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;{% set pop_posts = blog_popular_posts("default", 5, ["volvo", "saab"], "popular_past_month") %}&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;The client selects "Saab" and should then receive the blog posts corresponding to that selected tag "Saab".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I find information on how to do this on Hubspot?&lt;BR /&gt;&lt;BR /&gt;THANKS&lt;/P&gt;</description>
      <pubDate>Thu, 28 Apr 2022 18:02:46 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/How-to-use-javascript-variables-in-hubspot/m-p/623973#M28516</guid>
      <dc:creator>JVallejo7</dc:creator>
      <dc:date>2022-04-28T18:02:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to use javascript variables in hubspot</title>
      <link>https://community.hubspot.com/t5/CMS-Development/How-to-use-javascript-variables-in-hubspot/m-p/624011#M28519</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/331743"&gt;@JVallejo7&lt;/a&gt;,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;is there a reason why you don't want to use the "blog-tag-filter" module which comes (for example) with the theme "session" or any other default HubSpot theme. You could copy/paste it to your theme and modify it to your need&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;best,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anton&lt;/P&gt;</description>
      <pubDate>Thu, 28 Apr 2022 18:56:21 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/How-to-use-javascript-variables-in-hubspot/m-p/624011#M28519</guid>
      <dc:creator>Anton</dc:creator>
      <dc:date>2022-04-28T18:56:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to use javascript variables in hubspot</title>
      <link>https://community.hubspot.com/t5/CMS-Development/How-to-use-javascript-variables-in-hubspot/m-p/624287#M28526</link>
      <description>&lt;P&gt;Yes, because i want to do some other filters in my custom search filter and I need to show the blog post on the same page, not on another page like "&lt;SPAN&gt;blog-tag-filter" module&lt;/SPAN&gt;. I need something like AJAX.&lt;/P&gt;&lt;P&gt;But thank you !! i will review this module.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I have this listing and I need to load different post&amp;nbsp;in the function of the tag or other filters that the user select&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JVallejo7_0-1651216017441.png" style="width: 400px;"&gt;&lt;img src="https://community.hubspot.com/t5/image/serverpage/image-id/65151i80273CC53F30A0C9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JVallejo7_0-1651216017441.png" alt="JVallejo7_0-1651216017441.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Apr 2022 07:09:06 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/How-to-use-javascript-variables-in-hubspot/m-p/624287#M28526</guid>
      <dc:creator>JVallejo7</dc:creator>
      <dc:date>2022-04-29T07:09:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to use javascript variables in hubspot</title>
      <link>https://community.hubspot.com/t5/CMS-Development/How-to-use-javascript-variables-in-hubspot/m-p/624744#M28542</link>
      <description>&lt;P data-unlink="true"&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/331743"&gt;@JVallejo7&lt;/a&gt;&amp;nbsp;So if you really want a JavaScript solution (I would advise going for a React or Vue overview), you can get all blog posts with an API call using the &lt;A href="https://developers.hubspot.com/docs/cms/features/content-search" target="_blank"&gt;content search API&lt;/A&gt;. &lt;STRONG&gt;This does not need any authentication.&lt;/STRONG&gt; If you check the docs, you can pass a search term that causes the API to search all content on the blog post (or page). You can however limit this to a specific property like 'tag', which causes the API to only search for blog posts that have that specific tag. You can use the following URL (replace &amp;lt;PortalID&amp;gt; for your portal ID).&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;https://api.hubapi.com/contentsearch/v2/search?portalId=&amp;lt;PortalID&amp;gt;&amp;amp;term=saab&amp;amp;type=BLOG_POST&amp;amp;property=tag&lt;/P&gt;
&lt;P data-unlink="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P data-unlink="true"&gt;So in your case, you can use the following params:&amp;nbsp;&lt;/P&gt;
&lt;P data-unlink="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P data-unlink="true"&gt;&lt;STRONG&gt;&amp;amp;term=saab&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;amp;type=BLOG_POST&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;amp;property=tag&lt;/STRONG&gt;&lt;/P&gt;
&lt;P data-unlink="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P data-unlink="true"&gt;&lt;A href="https://api.hubapi.com/contentsearch/v2/search?portalId=62515&amp;amp;term=Topic%20Test%205cf8c042e9db8&amp;amp;property=tag" target="_blank" rel="noopener"&gt;Demo URL&lt;/A&gt; (this only has one blog post))&lt;/P&gt;</description>
      <pubDate>Fri, 29 Apr 2022 19:00:30 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/How-to-use-javascript-variables-in-hubspot/m-p/624744#M28542</guid>
      <dc:creator>Teun</dc:creator>
      <dc:date>2022-04-29T19:00:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to use javascript variables in hubspot</title>
      <link>https://community.hubspot.com/t5/CMS-Development/How-to-use-javascript-variables-in-hubspot/m-p/625607#M28554</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/331743"&gt;@JVallejo7&lt;/a&gt;,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Building off of&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/101258"&gt;@Teun&lt;/a&gt;'s suggestion of using the content search API, I put something quick together that I think achieves the basics of what you're looking for:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{% set my_tags = blog_tags('default', 250) %}


&amp;lt;select onchange="searchResults()" name="blog_tags" id="blog_tags"&amp;gt;
{% for item in my_tags %}
  &amp;lt;option value="{{item.name}}"&amp;gt;{{ item.name }}&amp;lt;/option&amp;gt;
{% endfor %}
&amp;lt;/select&amp;gt;

&amp;lt;div id="search-results"&amp;gt;&amp;lt;/div&amp;gt;

{%require_js %}
&amp;lt;script&amp;gt;
function searchResults() {
  var selectedTag =  document.getElementById('blog_tags').value;

  $.ajax({
    url: 'https://api.hubapi.com/contentsearch/v2/search?portalId={{ hub_id }}&amp;amp;property=tag&amp;amp;term='+selectedTag,
    type: 'GET',
    dataType: 'text',
    success: function(data) {
      var json_result = JSON.parse(data);
          
    let text = "";
const posts = json_result.results;
posts.forEach(printPosts);
    
    document.getElementById('search-results').innerHTML = text;
    
    function printPosts(item, index) {
  text += index + ": " + item['title'] + "&amp;lt;br&amp;gt;"; 
}
    }
  });
}
searchResults();
  &amp;lt;/script&amp;gt;
{%end_require_js %}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can further shape your results using the parameters here:&amp;nbsp;&lt;A href="https://legacydocs.hubspot.com/docs/methods/content/search-for-content" target="_blank" rel="noopener"&gt;https://legacydocs.hubspot.com/docs/methods/content/search-for-content&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 May 2022 18:36:22 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/How-to-use-javascript-variables-in-hubspot/m-p/625607#M28554</guid>
      <dc:creator>BarryGrennan</dc:creator>
      <dc:date>2022-05-02T18:36:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to use javascript variables in hubspot</title>
      <link>https://community.hubspot.com/t5/CMS-Development/How-to-use-javascript-variables-in-hubspot/m-p/625993#M28564</link>
      <description>&lt;P&gt;Thank you very much for your replies&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to check your codes but I don't know what´s going on:&lt;/P&gt;&lt;P&gt;This URL doesn't send me any response but I have post with events tag term&lt;/P&gt;&lt;P&gt;&lt;A href="https://api.hubapi.com/contentsearch/v2/search?portalId=25237078&amp;amp;term=test&amp;amp;type=BLOG_POST&amp;amp;property=tag" target="_blank" rel="noopener"&gt;https://api.hubapi.com/contentsearch/v2/search?portalId=25237078&amp;amp;term=events&amp;amp;type=BLOG_POST&amp;amp;property=tag&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://hubspot-developers-18iodbe-25237078.hs-sites-eu1.com/blogreformermodificado/tag/events" target="_blank" rel="noopener"&gt;http://hubspot-developers-18iodbe-25237078.hs-sites-eu1.com/blogreformermodificado/tag/events&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 03 May 2022 07:54:31 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/How-to-use-javascript-variables-in-hubspot/m-p/625993#M28564</guid>
      <dc:creator>JVallejo7</dc:creator>
      <dc:date>2022-05-03T07:54:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to use javascript variables in hubspot</title>
      <link>https://community.hubspot.com/t5/CMS-Development/How-to-use-javascript-variables-in-hubspot/m-p/626055#M28566</link>
      <description>&lt;P&gt;I have the robots.txt enable to this use&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JVallejo7_0-1651573209964.png" style="width: 400px;"&gt;&lt;img src="https://community.hubspot.com/t5/image/serverpage/image-id/65328iE4E1CD491A3DB0FA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JVallejo7_0-1651573209964.png" alt="JVallejo7_0-1651573209964.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 May 2022 10:20:25 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/How-to-use-javascript-variables-in-hubspot/m-p/626055#M28566</guid>
      <dc:creator>JVallejo7</dc:creator>
      <dc:date>2022-05-03T10:20:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to use javascript variables in hubspot</title>
      <link>https://community.hubspot.com/t5/CMS-Development/How-to-use-javascript-variables-in-hubspot/m-p/626300#M28569</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/331743"&gt;@JVallejo7&lt;/a&gt;,&amp;nbsp;I'm not fully clear what it is in your setup that's causing the standard api url to fail. But it seems if you change your endpoint to your domain instead you'll get the results you're looking for&lt;BR /&gt;&lt;A href="https://hubspot-developers-18iodbe-25237078.hs-sites-eu1.com/_hcms/search?portalId=25237078&amp;amp;property=tag&amp;amp;term=events" target="_blank" rel="noopener"&gt;https://hubspot-developers-18iodbe-25237078.hs-sites-eu1.com/_hcms/search?portalId=25237078&amp;amp;property=tag&amp;amp;term=events&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.hubspot.com/t5/APIs-Integrations/contentsearch-API-returning-nothing-for-private-membership-blog/td-p/566250" target="_blank" rel="noopener"&gt;This&amp;nbsp;post&lt;/A&gt;&amp;nbsp;seems to detail a similar problem with the search api and suggests it's something in the theme setup. I'm not entirely sure off the top of my head where that'd be set. But hopefully this stears you in the right direction!&lt;/P&gt;</description>
      <pubDate>Tue, 03 May 2022 16:27:52 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/How-to-use-javascript-variables-in-hubspot/m-p/626300#M28569</guid>
      <dc:creator>BarryGrennan</dc:creator>
      <dc:date>2022-05-03T16:27:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to use javascript variables in hubspot</title>
      <link>https://community.hubspot.com/t5/CMS-Development/How-to-use-javascript-variables-in-hubspot/m-p/626631#M28573</link>
      <description>&lt;P&gt;THANK YOU !&lt;BR /&gt;how did you know in this domain it's gonna work? Any thoughts that you can teach me?&lt;BR /&gt;Thanks again!&lt;/P&gt;</description>
      <pubDate>Wed, 04 May 2022 06:38:46 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/How-to-use-javascript-variables-in-hubspot/m-p/626631#M28573</guid>
      <dc:creator>JVallejo7</dc:creator>
      <dc:date>2022-05-04T06:38:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to use javascript variables in hubspot</title>
      <link>https://community.hubspot.com/t5/CMS-Development/How-to-use-javascript-variables-in-hubspot/m-p/626688#M28574</link>
      <description>&lt;P&gt;I have this error in the console when i try to use this code with the &lt;A href="https://hubspot-developers-18iodbe-25237078.hs-sites-eu1.com/_hcms/search?portalId=25237078&amp;amp;property=tag&amp;amp;term=events" target="_blank" rel="noopener"&gt;URL that you sent me&lt;/A&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Access to XMLHttpRequest at 'https://hubspot-developers-18iodbe-25237078.hs-sites-eu1.com/_hcms/search?portalId=25237078&amp;amp;&amp;amp;property=tag&amp;amp;term=events' from origin 'https://25237078.hubspotpreview-eu1.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 May 2022 08:38:32 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/How-to-use-javascript-variables-in-hubspot/m-p/626688#M28574</guid>
      <dc:creator>JVallejo7</dc:creator>
      <dc:date>2022-05-04T08:38:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to use javascript variables in hubspot</title>
      <link>https://community.hubspot.com/t5/CMS-Development/How-to-use-javascript-variables-in-hubspot/m-p/626720#M28575</link>
      <description>&lt;P&gt;I have noticed that hubspot doesn't support AJAX request&lt;/P&gt;&lt;P&gt;&lt;A href="https://stackoverflow.com/questions/48577247/hubspot-api-not-working-due-to-cors" target="_blank"&gt;https://stackoverflow.com/questions/48577247/hubspot-api-not-working-due-to-cors&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 04 May 2022 09:31:16 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/How-to-use-javascript-variables-in-hubspot/m-p/626720#M28575</guid>
      <dc:creator>JVallejo7</dc:creator>
      <dc:date>2022-05-04T09:31:16Z</dc:date>
    </item>
  </channel>
</rss>

