Show if content has matching string(s) in sequence

SOLVE
Highlighted
Esteemed Contributor | Platinum Partner

As of now, this only works when content.name has everything in the sequence defined below. 

 

For example, if the content's name was "lorem dolor is an ipsum," then it would work.

If it was "lorem said ipsum," then it would not print out a value (because it is missing "dolor").

{# ***********  VARIABLES ************ #}
{% set sequence_value = ['lorem', 'ipsum', 'dolor'] %}
{% set content_value = content.name %}

{# ************** CODE *************** #}
{% if content_value is string_containing sequence_value %}
          <div>foo</div>
{% endif %}

Hopefully this post will help someone else out in the future as well.



Will you please help the community and give me some street cred by marking my answer as a solution if helped you? I'm fixing to buy a minivan and my cool points are running low.

Curious cats can find me at Ascend Inbound Marketing

Reply
0 Upvotes
1 Accepted solution

Accepted Solutions
Highlighted
Solution
Esteemed Advisor | Partner

@John,

 

You will need to loop through "sequence_value" and check each item against your "content_value".

 

{# ***********  VARIABLES ************ #}
{% set sequence_value = ['lorem', 'ipsum', 'dolor'] %}

{# ************** CODE *************** #}
{% for content in contents %}

    {% for value in sequence_value %}

        {% if value in content.name %}

             {# OUTPUT #}

        {% endif %}

    {% endfor %}
{% endfor %}

I threw in the contents loop as I assumed you would need this applied. You can omit if needed.

 

Bare in mind that this will loop through each content and for each index of your content will loop through your sequence_value. If either or both set is relatively small then it won't be an issue but if both are large then it could add to your load time. 

 

*EDIT: I removed the content.name variable as it seamed redundant. Your var name was longer than the acutal token name and the var was declared outside of the contents for loop.

View solution in original post

3 Replies 3
Highlighted
Solution
Esteemed Advisor | Partner

@John,

 

You will need to loop through "sequence_value" and check each item against your "content_value".

 

{# ***********  VARIABLES ************ #}
{% set sequence_value = ['lorem', 'ipsum', 'dolor'] %}

{# ************** CODE *************** #}
{% for content in contents %}

    {% for value in sequence_value %}

        {% if value in content.name %}

             {# OUTPUT #}

        {% endif %}

    {% endfor %}
{% endfor %}

I threw in the contents loop as I assumed you would need this applied. You can omit if needed.

 

Bare in mind that this will loop through each content and for each index of your content will loop through your sequence_value. If either or both set is relatively small then it won't be an issue but if both are large then it could add to your load time. 

 

*EDIT: I removed the content.name variable as it seamed redundant. Your var name was longer than the acutal token name and the var was declared outside of the contents for loop.

View solution in original post

Highlighted
Esteemed Contributor | Platinum Partner

Thank you @Jsum, nice touch on the contents loop. You were right.

 

I do wonder what you'd consider too large / performance-hindering.

The sequence value will be a search that is stripped to a sequence of 7 values (duplicates also removed).

{% set sequence_value = request.query_dict.search|lower|split(' ', 7)|unique %}

 

Using this technique, would indexing each blog post's title be poor practice on a large blog?

To take it a step further, each blog post's entire content?



Will you please help the community and give me some street cred by marking my answer as a solution if helped you? I'm fixing to buy a minivan and my cool points are running low.

Curious cats can find me at Ascend Inbound Marketing

Reply
0 Upvotes
Highlighted
Esteemed Advisor | Partner

@John,

 

I am by no means an expert in efficiency, nor have I experience your exact circumstances so I couild not say whether it would be a hindrance or not. 

 

The way I see it though is that you have to loop through the contents anyways so all you are doing is adding a loop with 7 iterations to each iteration of the contents loop. The if statement inside the nested loop will cause the server to read the content.name per contents iteration. If you add the full blog content to be checked it would have to read all of the content per contents iteration. Either way this is done on the server side and, in my experience, Hubspot's servers have no problem processing a lot of logic quickly. I don't believe it will be an issue with just 7 nested iterations. All you can really do is set it up and check to ensure the page doesn't take much longer to load than it did originally. 

Reply
0 Upvotes