CMS Development

sgoodman
Participant | Platinum Partner
Participant | Platinum Partner

Display blogs with tags containing a space

SOLVE

Hi there, 

 

I am using the blog_recent_tag_post function to find blogs based on the tags entered by a user. It isn't working for any tags containing a space. For example, it will find blogs which have 'trending' as a tag but it won't find a blog that has 'most popular' as a tag. Can anyone tell me why this would be? Below is my code:

 

{% set input = request.query_dict.term %}
{% set tag_posts = blog_recent_tag_posts('default', input, 100) %} 
<div class = "search-results">
{% for tag_post in tag_posts %}
   <a href="{{tag_post.absolute_url}}" title="" class="result-link">
    <div class = "result-image-container">
      <img src="{{ tag_post.featured_image }}" alt=" image"/>
    </div>
     <div class = "result-about">
        <div class="result-tags">
         {% if tag_post.topic_list %}
        {% for topic in tag_post.topic_list %}
        {% if loop.first %}
        <span class="ed-tag">{{ topic.name }}</span>
        {% endif %}
        {% endfor %}
        {% endif %}
      </div>
       <div class="result-date">
          <p>{{ tag_post.publish_date_local_time|datetimeformat('%B %e, %Y') }}</p>
        </div>
      </div>
    <div class = "result-text-container">
      <h4>{{ tag_post.name }}</h4>
      <p class = "result-description">{{ tag_post.meta_description }}</p>

     </div>
    </a>
  {% endfor %}
</div>
0 Upvotes
1 Accepted solution
Ntbrown
Solution
Contributor

Display blogs with tags containing a space

SOLVE

Are you using the name or the slug? The function takes the slug. Space separated tag names when slugified have a "-".

View solution in original post

6 Replies 6
JVallejo7
Contributor

Display blogs with tags containing a space

SOLVE

I want to do exactly the same.

Can you tell me how do you get this information? 

request.query_dict.term

Thanks 

0 Upvotes
LucBenayoun
Participant

Display blogs with tags containing a space

SOLVE

Hey! 

 

Just use: 

{% set input = request.query_dict.term|lower|replace(" ", "-") %}

 

Cheers 🙂 

JVallejo7
Contributor

Display blogs with tags containing a space

SOLVE

Do you make this code dynamic without reloading the page (something like AJAX behavior) ? 

Can you teach me how can I do this?

Thanks

0 Upvotes
JVallejo7
Contributor

Display blogs with tags containing a space

SOLVE

THANKS !!

0 Upvotes
Ntbrown
Solution
Contributor

Display blogs with tags containing a space

SOLVE

Are you using the name or the slug? The function takes the slug. Space separated tag names when slugified have a "-".

dennisedson
HubSpot Product Team
HubSpot Product Team

Display blogs with tags containing a space

SOLVE

Hey @sgoodman ,

Are you still working on this?  @Anton , @Kevin-C , could you all lend a hand 🙏

0 Upvotes