<p>I figured this one out right after I posted it. </p>

<pre><code>{% set blogTag = craft.tags({ tag: tag, group: 'blogTags' }).first() %}
</code></pre>

<p>One mistake was searching for it with "name" instead of "tag". </p>

<p>The other mistake was that I needed to call first() to get the TagModel. Otherwise, craft.tags() just returns an ElementCriteriaModel.</p>

CC BY-SA 3.0
2014-08-12T17:30:26.640Z
2014-08-12T17:58:45.277Z
2014-08-12T17:58:45.277Z
Jason D
<p>I have a route that matches:</p>

<pre><code>/blog/tagged/{tag}
</code></pre>

<p>And in my template I would like to pull up all blogs that are related to the tag:</p>

<pre><code>{% if tag is defined %}
    {% set blogTag = craft.tags({ name: tag, group: 'blogTags' }) %}
    {% set filter = filter|merge({ relatedTo: blogTag }) %}
{% endif %}

{% for entry in craft.entries(filter).find() %}
</code></pre>

<p>But this doesn't work since craft.tags() gives me an ElementCriteriaModel, but I need a TagModel to work with relatedTo(). </p>

<p>I can't figure out how to get the TagModel here.</p>

<tags>
How do you get ahold of a TagModel in a template?
# How do you get ahold of a TagModel in a template?

(Asked by: username_0 on 2014-08-12)

I have a route that matches:
/blog/tagged/{tag}

And in my template I would like to pull up all blogs that are related to the tag:
{% if tag is defined %}
    {% set blogTag = craft.tags({ name: tag, group: 'blogTags' }) %}
    {% set filter = filter|merge({ relatedTo: blogTag }) %}
{% endif %}

{% for entry in craft.entries(filter).find() %}

But this doesn't work since craft.tags() gives me an ElementCriteriaModel, but I need a TagModel to work with relatedTo(). 
I can't figure out how to get the TagModel here.

**Tags:** tags


---

## 1 answers

### Answer by username_0 on 2014-08-12. Score: 2

I figured this one out right after I posted it. 
{% set blogTag = craft.tags({ tag: tag, group: 'blogTags' }).first() %}

One mistake was searching for it with "name" instead of "tag". 
The other mistake was that I needed to call first() to get the TagModel. Otherwise, craft.tags() just returns an ElementCriteriaModel.


---

