2

So I have /calendar and linking previous/next months on that template. The previous/next month urls are /calendar/2015-08 and /calendar/2015-08.

I have this custom route setup:

enter image description here

On my /calendar/2015-08 I'm getting this:

Variable "entry" does not exist

Part of my template looks like:

{% extends '_inc/_layout' %}

{% block meta %}
<title>{% if entry.metaTitle|length %}{{ entry.metaTitle }}{% else %}{{ entry.title }}{% endif %}</title>
<meta name="description" content="{{ entry.metaDescription }}" />
<meta name="keywords" content="{{ entry.metaKeywords }}" />
{% endblock %}

I know why this happening but my question is how do I circumvent this? I want some of the same data on /calendar to be on subsequent monthly calendar pages.

Thanks in advance!

  • What does entry refer to in this case? Is /calendar the Entry URL for an entry, and is that the entry you need to access on the other pages? – Michael Rog Jul 2 '15 at 21:59
  • /calendar works since it's a structure entry. so yes need that data passed down to other calendar pages. – Mark Busnelli Jr Jul 2 '15 at 22:02
3

Craft won't set the entry variable automatically unless the route matches a particular entry. If you're sharing a template between routes that may or may not correspond to an entry, you need to make sure that var gets set explicitly by you if not automatically by Craft:

{% if entry is not defined %}
    {% set entry = craft.entries.section('myStructure').slug('calendar').first %}
{% endif %}
  • Does't like that Unexpected token "punctuation" of value ":" ("end of statement block" expected) – Mark Busnelli Jr Jul 2 '15 at 22:08
  • The ?: is backwards: twig.sensiolabs.org/doc/templates.html#other-operators – Lindsey D Jul 2 '15 at 22:11
  • hmm now getting Variable "entry" does not exist. but the parent /calendar` is working` – Mark Busnelli Jr Jul 2 '15 at 22:16
  • @Mark I edited the example to include is not defined. And it was getting a little long for a ternary, so I converted it to a traditional if statement. – Lindsey D Jul 2 '15 at 22:50
  • that did it! thx again – Mark Busnelli Jr Jul 2 '15 at 23:23

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.