Question

Photo of Ben Goshow

0

Dynamic filtering content channel items based on Attribute value

I've created a defined type "Tags" for my Content Channel "Blog" and I can assign multiple Tags to a blog post.

I have tried everything but I can't get the URL query/parameter filtering or Lava to allow me to then display a list of posts that have that tag assigned.

  • Eddie Holeman

    Ben, I am trying to accomplish the same thing in filtering a staff directory content channel by department, but my ?Dept=Operations type of filter also returns nothing. Have you found any answer to this?

  • Nate Hoffman

    Hey Eddie, your page should filter just fine because you are using a multi-select, it is ?<key>=<value> for the parameter, since I know your setup it is <yoururl>?MinistryTeam=Connections looks like it is filtering just fine to me. As for Ben's original question he is using a defined type and I would have to test to see if it works the same, I believe the issue is that it is either expecting a GUID or an ID for the defined type as the value.

  • Eddie Holeman

    Thanks Ben. I failed to mention that I was using a defined type. We did some testing yesterday with a mult-select attribute and all works well. I would prefer a defined type, so will keep reading below.

  • Ben Goshow

    Let me know if you figure it out and I'll change the solution to fit my original question.

  • Photo of Ben Goshow

    0

    Nate is right. With help from Arran France, we determined that I needed to use a multi-select attribute instead of a defined type.

    • Ben Goshow

      I was able to use Nate's suggestion to parse out the active tags with another content channel view. Here's the code I used to build the select filter of unique tags, sorted by name:


              {% capture postTags %}{% for item in Items %}{{ item | Attribute: &#39;Tags&#39;}},{% endfor %}{% endcapture %}
      {% assign blogTags = postTags | ReplaceLast:&#39;,&#39;,&#39;&#39; | Split:&#39;,&#39; | Sort %}
      &lt;select name=&quot;tags&quot; class=&quot;filter form-control&quot;&gt;
      &lt;option selected&gt;Tags&lt;/option&gt;
      {% assign thisTag = &#39;&#39; %}
      {% for tag in blogTags %}
      {% if tag != thisTag %}
      &lt;option value=&quot;{{ tag }}&quot;&gt;{{ tag }}&lt;/option&gt;
      {% endif %}
      {% assign thisTag = tag %}
      {% endfor %}
      &lt;/select&gt;
  • Photo of Nate Hoffman

    0

    I did figure out you can use defined types, but they are quite specific and require GUID's. If you wanted to still use a defined type you could use the "Defined Value List Lava" block with something like this code: 

    <ul>
    {% for definedValue in DefinedValues %}
        <li><a href="?Audience={{ definedValue.Guid }}">{{ definedValue.Value }}</a></li>
    {% endfor %}
    </ul>

    Though with multi-select from my tests did not work with defined types, if I selected multiple, my URL would have to contain the multiple selections to filter to that specific item. I think it is just a very specific filter on the content channel view block.

    • Ben Goshow

      Thanks Nate! Btw, is there a Lava block to list out the values from my multi-select "Tags" attribute? I'm trying to create a dropdown filter so viewers can specify the tag they want to view.

    • Nate Hoffman

      Not that easily, the only way I would consider doing it is using the dynamic data block which requires SQL, but you would have to figure out where those values are stored and parse them out yourself. If they change enough it would probably be worth it though. You could also try to just parse out all items in your content channel in lava with an additional content channel view block and put together a list that way, that way it is only tags that are actually used, otherwise I would just hard code them for now.