Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-01T18:41:30.827Z
Answers.Text: 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)
Answers.UserDisplayName: Michael Rog
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-01T18:14:47.987Z
Answers.LastActivityDate: 2015-02-01T18:14:47.987Z
Answers.UserDisplayName: Michael Rog
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-06T12:21:08.113Z
Answers.Text: 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?
Answers.UserDisplayName: Romain P.
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-06T13:22:40.783Z
Answers.Text: @Romainpoirier Just added `.first()` to the 2nd line of the first code block. That should fix your error.
Answers.UserDisplayName: Brandon Kelly
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-06T10:54:21.117Z
Answers.LastActivityDate: 2014-07-06T13:21:59.010Z
Answers.LastEditDate: 2014-07-06T13:21:59.010Z
Answers.UserDisplayName: Victor
Body: <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>
  
Tags: <entry-type>
Title: How do I create a link to an entry using entry's id?
ThreadText: # 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](http://buildwithcraft.com/docs/templating/craft.entries) to fetch the [EntryModel](http://buildwithcraft.com/docs/templating/entrymodel), and than output its url:
  
  ```twig
  {% 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:
  
  ```twig
  {% 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](http://buildwithcraft.com/docs/reference-tags) along with the `parseRefs` filter, like this:
  
  ```
  <a href="{{ '{entry:123:url}' | parseRefs }}">{{ '{entry:123:title}' | parseRefs }}</a>
  
  ```
  
  (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)  
  
  ---
  
  