This won't work in a template:

{% set entry = craft.entries.id(43) %}<h1>Titel: {{ entry.title }}</h1>

But this does:

{% for entry in craft.entries.id(43) %}<h1>Titel: {{ entry.title }}</h1>{% endfor %}

Is it really necessary to use the for loop? I tried to use set because I'd like to over rule the entry variable for the whole template that I'm using if a specific url is visited

{% if craft.request.segment(2)=="openings-en-trainingstijden" %} {% set entry = craft.entries.id(43) %}{% endif %} {{ entry.title }} etc..

Another example this code:

{% for entry1 in craft.entries.id(43) %}Titel: {{ entry1.title }}{% endfor %}
{% set entry2 = craft.entries.id(43) %}Titel: {{ entry2.title }}

Results in:

Titel: Openings- en trainingstijden

You need to add .first where you are setting the entry variable:

{% set entry = craft.entries.id(43).first %}

That way you can avoid doing a for loop.


Your first line must work. But there is a typo with double ))

{% set entry = craft.entries.id(43).first() %}

{{ entry.title}}

But normally when you add a template for a specific single you doesn't have to set the entry.

  • I'm afraid it doesn't... even with a single )
    – noregt
    Nov 22 '16 at 16:20
  • Sorry forgot the .first() Nov 22 '16 at 16:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.