<p>Craft won't set the <code>entry</code> 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:</p>

<pre><code>{% if entry is not defined %}
    {% set entry = craft.entries.section('myStructure').slug('calendar').first %}
{% endif %}
</code></pre>

CC BY-SA 3.0
2015-07-02T22:08:22.470Z
Does't like that `Unexpected token "punctuation" of value ":" ("end of statement block" expected)`
Mark Busnelli Jr
CC BY-SA 3.0
2015-07-02T22:11:20.893Z
The `?:` is backwards: http://twig.sensiolabs.org/doc/templates.html#other-operators
Lindsey D
CC BY-SA 3.0
2015-07-02T22:16:57.233Z
hmm now getting `Variable "entry" does not exist. but the parent `/calendar` is working`
Mark Busnelli Jr
CC BY-SA 3.0
2015-07-02T22:50:31.773Z
@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
CC BY-SA 3.0
2015-07-02T23:23:21.580Z
that did it! thx again
Mark Busnelli Jr
CC BY-SA 3.0
2015-07-03T16:46:38.427Z
That's what I get for trying to be too terse. Thanks, @LindseyD!
Michael Rog
CC BY-SA 3.0
2015-07-02T22:06:16.720Z
2015-07-02T22:49:12.860Z
2015-07-02T22:49:12.860Z
Michael Rog
<p>So I have <code>/calendar</code> and linking previous/next months on that template. The previous/next month urls are <code>/calendar/2015-08</code> and <code>/calendar/2015-08</code>.</p>

<p>I have this custom route setup:</p>

<p><img src="https://i.sstatic.net/SFz3u.png" alt="enter image description here"></p>

<p>On my <code>/calendar/2015-08</code> I'm getting this:</p>

<p><code>Variable "entry" does not exist</code></p>

<p>Part of my template looks like:</p>

<pre><code>{% extends '_inc/_layout' %}

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

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

<p>Thanks in advance!</p>

CC BY-SA 3.0
2015-07-02T21:59:10.247Z
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
CC BY-SA 3.0
2015-07-02T22:02:55.110Z
`/calendar` works since it's a structure entry. so yes need that data passed down to other calendar pages.
Mark Busnelli Jr
<children><calendar><parents>
Monthly Calendar || Month View
# Monthly Calendar || Month View

(Asked by: username_0 on 2015-07-02)

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:

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 %}
{% if entry.metaTitle|length %}{{ entry.metaTitle }}{% else %}{{ entry.title }}{% endif %}


{% 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!

**Tags:** children, calendar, parents

> **Comments:**
> **username_1**: 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?  
> **username_0**: `/calendar` works since it's a structure entry. so yes need that data passed down to other calendar pages.  

---

## 1 answers

### Answer by username_1 on 2015-07-02. Score: 3 | Accepted answer

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 %}

> **Comments:**
> **username_0**: Does't like that `Unexpected token "punctuation" of value ":" ("end of statement block" expected)`  
> **username_2**: The `?:` is backwards: http://twig.sensiolabs.org/doc/templates.html#other-operators  
> **username_0**: hmm now getting `Variable "entry" does not exist. but the parent `/calendar` is working`  
> **username_2**: @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.  
> **username_0**: that did it! thx again  
> **username_1**: That's what I get for trying to be too terse. Thanks, @LindseyD!  

---

