0

So I have my dinnermenu at example.com/dinnermenu but I want to show specific content for the next week if someone asks for it via example.com/dinnermenu/nextWeek but it should still use the entry data from dinnermenu ...

how can I achieve that ?

2

There are a lot of ways to go about this depending on how you have your sections and templates set up, and where you are getting your content from for both 'dinnermenu' and 'nextweek'.

Using routes

If you just want 'dinnermenu/nextweek' requests to be directed to the 'dinnermenu' template, then one option would be to set up a dynamic route with a '*' token as the last segment (i.e. dinnermenu/*). This would route example.com/dinnermenu/any-uri-segment to your 'dinnermenu' template ('dinnermenu.html' or 'dinnermenu/index.html' or whatever you called it).

In the dinnermenu template you can then test for the uri segment and display custom 'nextweek' content, in addition to (or instead of) your dinner menu content.

{% if craft.request.segments(2) == 'nextweek' %}
    // display content for next week
{% endif %}

See craft.request for more info.

Using a structure

For more dynamic nav you could also use a 'structure' (with 2 levels). In the template you can then test for the level and include the parent content as needed.

{% switch entry.level %}
    {% case "1" %}
        {% set dinnermenu = entry %}
    {% case "2" %}
        {% set dinnermenu = entry.parent %}
{% endswitch %}

{{ entry.intro }}     // dinnermenu's or nextweek's 'intro' field
{{ dinnermenu.body }} // with dinnermenu's body field

Using ElementCriteriaModel

If on the other hand, you want to pull your 'dinnermenu' entry into your 'nextweek' template (no matter where it is), then you can use an EntryCriteriaModel to retrieve and display the 'dinnermenu' entry.

{% set dinnermenu = craft.entries.slug('dinnermenu').first %}
{{ dinnermenu.body }}
etc.

You could also just include the whole 'dinnermenu' template in the 'nextweek' template.

{% set entry = craft.entries.slug('dinnermenu').first %}
{% include 'dinnermenu.html' %}

Lot of options.

| improve this answer | |
  • I tried the route method - but then it can't access my data in the entry tag somehow – maxx Nov 23 '14 at 1:46
  • 1
    Just set it manually. {% set entry = craft.entries.section('mysection').slug('dinnermenu').first %} – Douglas McDonald Nov 23 '14 at 2:38
  • perfect :) that was what I needed – maxx Nov 23 '14 at 16:29
  • Great! maybe mark this as correct then – Douglas McDonald Nov 23 '14 at 16:45

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.