Answers.Body: <p>It's because of #2 here: <a href="https://docs.craftcms.com/v3/routing.html#dynamic-routes" rel="nofollow noreferrer">https://docs.craftcms.com/v3/routing.html#dynamic-routes</a></p>
  
  <p><code>index.html</code> matches a route (likely you've got a Single section defined in Settings setup to load the index.html template).  Because of that, Craft will prepopulate the <code>entry</code> variable for that route in the template.</p>
  
  <p>There currently isn't a route that matches <code>preview/index.html</code>, so Craft doesn't prepopulate the <code>entry</code> variable and you get the error you're seeing.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-11T23:36:22.160Z
Answers.Text: Ah-ha! Thank you- that's extremely useful information. So here's one more, related question- if I have an `index.html` file in a `preview` folder as described above, how might I go about defining a route/section that is able to populate the `entry` variable in the same way as the homepage- is this possible? Or would I need to manually define scope for the variable? Thanks again! *as a side note, I'm seeing there aren't any actual routes defined in settings, however, I do see an entry for `Homepage` in Settings > Sections —is this how the template is able to pre-populate that variable?
Answers.UserDisplayName: nickpish
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-11T23:11:41.353Z
Answers.LastActivityDate: 2019-07-11T23:11:41.353Z
Answers.UserDisplayName: Brad Bell
Body: <p>I've inherited a Craft-based website, and I'm much more familiar with WordPress, so please pardon the extremely basic question: the homepage for this site uses <code>{% extends "_layout" %}</code> and then references some field data associated with an entry (within "Singles") for "Homepage". I wanted to create a duplicate page to experiment with the template syntax, so I literally copied the contents of <code>index.html</code> into another file of the same name in a folder labeled "preview". Now, if I visit the site via <code>www.site.org/preview</code> I get the following error:</p>
  
  <pre><code>Internal Server Error
  Undefined index: entry
  </code></pre>
  
  <p>I have tried numerous ways of identifying the source of the entries, e.g. <code>set entries</code> but I can't seem to get the field data to output. Of course, if I remove any reference to entry data, the rest of the template renders fine. Why on earth would simply duplicating the homepage file result in the above undefined error? I've tried re-indexing the site assets, clearing caches, etc. Thanks for any assistance here- I'm at my wits' end.</p>
  
Tags: <templating><entries-field>
Title: Undefined index error in trying to duplicate file
ThreadText: # Undefined index error in trying to duplicate file
  
  (Asked by: username_0 on 2019-07-10)
  
  I've inherited a Craft-based website, and I'm much more familiar with WordPress, so please pardon the extremely basic question: the homepage for this site uses `{% extends "_layout" %}` and then references some field data associated with an entry (within "Singles") for "Homepage". I wanted to create a duplicate page to experiment with the template syntax, so I literally copied the contents of `index.html` into another file of the same name in a folder labeled "preview". Now, if I visit the site via `www.site.org/preview` I get the following error:
  
  ```
  Internal Server Error
  Undefined index: entry
  
  ```
  
  I have tried numerous ways of identifying the source of the entries, e.g. `set entries` but I can't seem to get the field data to output. Of course, if I remove any reference to entry data, the rest of the template renders fine. Why on earth would simply duplicating the homepage file result in the above undefined error? I've tried re-indexing the site assets, clearing caches, etc. Thanks for any assistance here- I'm at my wits' end.
  
  **Tags:** templating, entries-field
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-07-11. Score: 0 | Accepted answer
  
  It's because of #2 here: <https://docs.craftcms.com/v3/routing.html#dynamic-routes>
  
  `index.html` matches a route (likely you've got a Single section defined in Settings setup to load the index.html template). Because of that, Craft will prepopulate the `entry` variable for that route in the template.
  
  There currently isn't a route that matches `preview/index.html`, so Craft doesn't prepopulate the `entry` variable and you get the error you're seeing.
  
  > **Comments:**
  > **username_0**: Ah-ha! Thank you- that's extremely useful information. So here's one more, related question- if I have an `index.html` file in a `preview` folder as described above, how might I go about defining a route/section that is able to populate the `entry` variable in the same way as the homepage- is this possible? Or would I need to manually define scope for the variable? Thanks again! *as a side note, I'm seeing there aren't any actual routes defined in settings, however, I do see an entry for `Homepage` in Settings > Sections —is this how the template is able to pre-populate that variable?  
  
  ---
  
  