Custom Blog Search in Hubspot COS

Dec 14, 2016 | 4 minute read

Hubspot does not provide you with any search engine for your blogs, instead pointing you to use Google search. I have prepared a very simple solution which you can use to create good looking search without redirecting your visitors to external websites. Check out working example at

Its fast, quick and simple, but has two disadvantages - search is capped to 200 most popular blogposts and it looks through post titles only. More advanced solution will require some changes in the code below.

Custom template for search results

You need to create a new page for search results with custom template. Im using as URL. You will redirect users to this page with parameter q (query), ex.

Here is an example code for search template:

{% raw %}{# you can replace 'default' with your blog id #}
{% set contents = blog_popular_posts('default', 200) %}

{# search query #}
{% set query = request.query_dict['q'] %}

<h1>Search results for: {{ query }}</h1>
{% for content in contents %}
  {% if query|lower in|lower %}
    <h2><a href="{{ content.absolute_url }}">{{ }}</a></h2>
    <p>{{ content.post_summary|striptags }}</p>
  {% endif %}
{% endfor %}{% endraw %}

All available content variables are described in HubL supported variables.

Blog search form

How to redirect user to proper search results? Just create a simple HTML form which will serve a search bar:

<form action="">
  <input type="search" name="q" placeholder="Search">

If you need something more sophisticated, I recommend you to dive into HubL documentation and start hacking.

Hubspot Marketing Automation Netguru