I have been building a module to display specific content based on the URL parameter that appears in the URL.
The module will allow the user to input a URL parameter in a text field and add content to a rich text field both in a repeatable field group.
The current issue I've run into is when checking the values to see if they are the same (which would trigger the content to appear) the check returns a false value, even though the values are the same.
Would love to get some thoughts on why this isn't working or how it can be improved.
{% set url_check = request.query_dict.content %}
{% set constant = "test" %}
{% for item in module.add_content %}
{% set url_param = "{{item.url_parameter}}" %}
<div class="URL-content">
<!-- Checking values against eachother -->
print url parameter before IF statement: {{item.url_parameter}} <br/>
print url_check: {{url_check}} <br/>
print url_param: {{url_param}} <br/>
print constant: {{constant}} <br/>
URL_check = url_param: {{ url_check == url_param }} <br/>
URL_check = constant: {{ url_check == constant }} <br/>
URL_param = constant: {{ url_param == constant }} <br/>
{% if url_param is equalto url_check %}
<div>
Test not using content rich text
{{item.content}}</div>
{% endif %}
</div>
{% endfor %}
You are trying to compare a string with the URL param, which should work, but maybe the URL param is not a string so that is why your if statement isn't working.
Learn more about HubSpot by following me on LinkedIn or YouTube
✅ Did my answer solve your issue? Help the community by marking it as the solution.
Thanks Teun, it looks like each value is a string so it should be working.
I've managed to make this module work by putting the {% set url_param = "test" %} code directly into the url_parameter text field. So instead of just typing in the desired URL parameter, the user will need to replace "test" with the parameter instead. (not ideal but it works).
The code now looks like this:
{% set url_check = request.query_dict.content %}
{% set constant = "test" %}
{{module.text_field}}
{% for item in module.add_content %}
{{item.url_parameter}}
<div class="URL-content">
{% if url_check == url_param %}
<div>{{item.content}}</div>
{% endif %}
</div>
{% endfor %}