# HubL & Query String

**URL:** <https://community.hubspot.com/t/hubl-query-string/3002>\
**Category:** CMS Development\
**Created:** [August 10, 2017, 10:56pm UTC](https://community.hubspot.com/t/hubl-query-string/3002 "2017-08-10T22:56:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![dtysick](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dtysick/32/104451_2.png) [@dtysick](https://community.hubspot.com/u/dtysick)\
**Post date:** [August 10, 2017, 10:56pm UTC](https://community.hubspot.com/t/hubl-query-string/3002/1 "2017-08-10T22:56:00Z")

</div>

I’m trying to set up a page so that it will personalize some content based on the query string. For example, if the query string is ?company=xyz, I would want the H1 to show up as “Welcome XYZ”

Here are the steps I took

1) Add custom HubL to a template: \<h1\>Welcome {{ request.query.company|default(‘Acme Corp’)}}\</h1\>

2) Add the query string of ?company=xyz to the end of the url and test

The result is always the default of “Acme Corp” instead of what is in the query string. Any idea what I am doing wrong?

---

<div class="post-metadata">

**Author:** ![Jsum](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jsum/32/20405_2.png) [@Jsum](https://community.hubspot.com/u/Jsum)\
**Post date:** [August 10, 2017, 11:10pm UTC](https://community.hubspot.com/t/hubl-query-string/3002/2 "2017-08-10T23:10:15Z")

</div>

@dtysick,

Try setting your query to a variable and outputting that variable onto your page first:

```auto
{% set query = request.query_dict.company %}

<p class="random_paragraph">
 {{ query }}
</p>

```

If it outputs, then try it without the filter:

`<h1> Welcome {{ query }} </h1>`

Then apply the filter again:

`<h1> Welcome {{ query|default('Acme Corp') }} </h1>`

Fact is there aren’t to many things that can go wrong with something simple like this so strip it down to its most basic. It could possibly have something to do with the missing space in your h1.

---

<div class="post-metadata">

**Author:** ![dtysick](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dtysick/32/104451_2.png) [@dtysick](https://community.hubspot.com/u/dtysick)\
**Post date:** [August 11, 2017, 8:23pm UTC](https://community.hubspot.com/t/hubl-query-string/3002/3 "2017-08-11T20:23:08Z")

</div>

Thanks! Made a small change and got it to work.

Is there an easy to way pass the query string to other pages as well? For example, they arrive at [acme.com/product?company=test](http://acme.com/product?company=test) and they then click on pricing in the nav. I’d like the personalization to continue to that page so I would need the url to be [acme.com/pricing?company=test](http://acme.com/pricing?company=test).

---

<div class="post-metadata">

**Author:** ![Jsum](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jsum/32/20405_2.png) [@Jsum](https://community.hubspot.com/u/Jsum)\
**Post date:** [August 11, 2017, 8:27pm UTC](https://community.hubspot.com/t/hubl-query-string/3002/4 "2017-08-11T20:27:04Z")

</div>

@dtysick,

check out these [http variables](http://designers.hubspot.com/docs/hubl/hubl-supported-variables#http-request-variables).

You should be able to add a variable behind your urls so that the urls always have the current query appended. This might be more difficult for advanced menus. You could also use javascript to capture the query and append it to all links on the page.

---

<div class="post-metadata">

**Author:** ![dtysick](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dtysick/32/104451_2.png) [@dtysick](https://community.hubspot.com/u/dtysick)\
**Post date:** [August 11, 2017, 8:41pm UTC](https://community.hubspot.com/t/hubl-query-string/3002/5 "2017-08-11T20:41:59Z")

</div>

Thanks for such a quick reply @Jsum. I’m not great with Javascript but I’ll look around online and see if I can find something to modify.

---

<div class="post-metadata">

**Author:** ![Jsum](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jsum/32/20405_2.png) [@Jsum](https://community.hubspot.com/u/Jsum)\
**Post date:** [August 11, 2017, 8:45pm UTC](https://community.hubspot.com/t/hubl-query-string/3002/6 "2017-08-11T20:45:19Z")

</div>

no problem. I understand, it’s not exactly common practice javascript, at least not to me. Here a stack exchange post on the subject:

> <https://stackoverflow.com/questions/11526102/jquery-append-querystring-to-all-links>

---

<div class="post-metadata">

**Author:** ![dtysick](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dtysick/32/104451_2.png) [@dtysick](https://community.hubspot.com/u/dtysick)\
**Post date:** [August 11, 2017, 8:55pm UTC](https://community.hubspot.com/t/hubl-query-string/3002/7 "2017-08-11T20:55:32Z")

</div>

Thanks! I actually found some jQuery that does the job pretty well:

\<script\>$(“a”).click(function(e) {  
e.preventDefault();

var params = window.location.search,  
dest = $(this).attr(‘href’) + params;

// in my experience, a short timeout has helped overcome browser bugs  
window.setTimeout(function() {  
window.location.href = dest;  
}, 100);  
});  
\</script\>
