<p>As a shorthand, you could also use <a href="http://buildwithcraft.com/docs/reference-tags" rel="nofollow">Reference Tags</a> along with the <code>parseRefs</code> filter, like this:</p>

<pre><code>&lt;a href="{{ '{entry:123:url}' | parseRefs }}"&gt;{{ '{entry:123:title}' | parseRefs }}&lt;/a&gt;
</code></pre>

<p>(Performance-wise, I'm not actually sure how this compares to spinning up the ElementCriteriaModel. It wouldn't surprise me if Craft caches entry data it queries, so it's not running a separate query for each reference tag... but I'm not sure about that.)</p>

CC BY-SA 3.0
2015-02-01T18:41:30.827Z
Question about whether this is performant, posted here: [http://craftcms.stackexchange.com/questions/6906/linking-to-specific-entries-in-twig-how-performant-is-reference-tags-parsing](http://craftcms.stackexchange.com/questions/6906/linking-to-specific-entries-in-twig-how-performant-is-reference-tags-parsing)
Michael Rog
CC BY-SA 3.0
2015-02-01T18:14:47.987Z
2015-02-01T18:14:47.987Z
Michael Rog
<p>The reason why your example fail is that you are using the <code>entry</code> variable. You are trying to call the function <code>getUrl</code> on the model <code>entry</code>, but the function (or model) doesn't exist yet, and has to be created (fetched).</p>

<p><strong>Example:</strong></p>

<p>You can use <a href="http://buildwithcraft.com/docs/templating/craft.entries" rel="nofollow">craft.entries</a> to fetch the <a href="http://buildwithcraft.com/docs/templating/entrymodel" rel="nofollow">EntryModel</a>, and than output its url:</p>

<pre class="lang-twig prettyprint-override"><code>{% set my_id = 5 %}
{% set entry = craft.entries.id(my_id).first() %}
{{ entry.url }}
</code></pre>

<p>If you are in an entry loop, it works the same way:</p>

<pre class="lang-twig prettyprint-override"><code>{% for entry in craft.entries.section('blog') %}
    {{ entry.url }}
{% endfor %}
</code></pre>

CC BY-SA 3.0
2014-07-06T12:21:08.113Z
Thanks! I tried to add this link but all I got is a PHP error: CException — Craft\ElementCriteriaModel and its behaviors do not have a method or closure named "url". Same problem after chaining the 'entry' and 'my_id'. Any idea?
Romain P.
CC BY-SA 3.0
2014-07-06T13:22:40.783Z
@Romainpoirier Just added `.first()` to the 2nd line of the first code block. That should fix your error.
Brandon Kelly
CC BY-SA 3.0
2014-07-06T10:54:21.117Z
2014-07-06T13:21:59.010Z
2014-07-06T13:21:59.010Z
Victor
<p>This is a beginner question:</p>

<p><strong>How do I create a link to an entry using entry's id?</strong></p>

<p>I tried several combinations, such as <code>{{ entry.getUrl(my_id) }}</code>, <code>{{ entry.url.id(my_id) }}</code>, etc. but failed to found the correct syntax.</p>

<entry-type>
How do I create a link to an entry using entry's id?
# How do I create a link to an entry using entry's id?

(Asked by: username_0 on 2014-07-06)

This is a beginner question:

**How do I create a link to an entry using entry's id?**

I tried several combinations, such as `{{ entry.getUrl(my_id) }}`, `{{ entry.url.id(my_id) }}`, etc. but failed to found the correct syntax.

**Tags:** entry-type


---

## 2 answers

### Answer by username_2 on 2014-07-06. Score: 4 | Accepted answer

The reason why your example fail is that you are using the entry variable. You are trying to call the function getUrl on the model entry, but the function (or model) doesn't exist yet, and has to be created (fetched).
Example:
You can use craft.entries to fetch the EntryModel, and than output its url:
{% set my_id = 5 %}
{% set entry = craft.entries.id(my_id).first() %}
{{ entry.url }}

If you are in an entry loop, it works the same way:
{% for entry in craft.entries.section('blog') %}
    {{ entry.url }}
{% endfor %}

> **Comments:**
> **username_0**: Thanks! I tried to add this link but all I got is a PHP error: CException — Craft\ElementCriteriaModel and its behaviors do not have a method or closure named "url". Same problem after chaining the 'entry' and 'my_id'. Any idea?  
> **username_3**: @Romainpoirier Just added `.first()` to the 2nd line of the first code block. That should fix your error.  

---

### Answer by username_1 on 2015-02-01. Score: 2

As a shorthand, you could also use Reference Tags along with the parseRefs filter, like this:
{{ '{entry:123:title}' | parseRefs }}

(Performance-wise, I'm not actually sure how this compares to spinning up the ElementCriteriaModel. It wouldn't surprise me if Craft caches entry data it queries, so it's not running a separate query for each reference tag... but I'm not sure about that.)

> **Comments:**
> **username_1**: Question about whether this is performant, posted here: [http://craftcms.stackexchange.com/questions/6906/linking-to-specific-entries-in-twig-how-performant-is-reference-tags-parsing](http://craftcms.stackexchange.com/questions/6906/linking-to-specific-entries-in-twig-how-performant-is-reference-tags-parsing)  

---

