Tag to fetch URL and Title of a entry when supplied it's ID I have a number of places in my templates where a link to a particular entry is needed to be hardcoded into the template, but we still want that links URL and title to be dynamic, so if the URL or Title of the entry is updated, this is reflected.

Is there a nice lightweight simple snipped of code we can use to fetch the URL and Title of an entry when supplied with a valid entry ID? I've checked through the documentation but can't see anything obvious. 

Particularly after something lightweight that isn't going to add significant numbers of DB queries to a page load.
This is all you need:

{% set linkedEntry = craft.entries.id(42).first() %}
&lt;a href="{{ linkedEntry.url }}"&gt;{{ linkedEntry.title }}&lt;/a&gt;


If you use this in many places you can also make a macro.

{% macro linkToEntry(entryId) %} 

    {# Get the entry with the selected ID #}
    {% set linkedEntry = craft.entries.id(entryId).first() %}

    {# Make sure the entry exists and output the link #}
    {% if linkedEntry %}
        &lt;a href="{{ linkedEntry.url }}"&gt;{{ linkedEntry.title }}&lt;/a&gt;
    {% endif %}

{% endmacro %}


It's nice to have macros in a separate file and import it into your templates. I really love using macros for this kind of code snippets, very useful and DRY.

{% import "macros.html" as macros %}

&lt;li&gt;{{ macros.linkToEntry(42) }}&lt;/li&gt;
&lt;li&gt;{{ macros.linkToEntry(17) }}&lt;/li&gt;
&lt;li&gt;{{ macros.linkToEntry(20) }}&lt;/li&gt;