statamic / v2-hub

Statamic 2 - Feature Requests and Bug Reports
https://statamic.com
95 stars 5 forks source link

Custom 404 error page not working #2180

Open jimblue opened 5 years ago

jimblue commented 5 years ago

Describe the bug Statamic crash when I switch from default 404 template to a custom one. I've follow the documentation by creating a /errors/404.html template.

The error summary

FatalThrowableError in LocalesTags.php line 97:
Call to a member function in() on null

and

A link to the full error message

To Reproduce Steps to reproduce the behavior:

  1. Create an errors folder in the templates folder
  2. Create a new 404.html file in the newly created errors folder
  3. Browse to an url that should trigger a 404
  4. See error

Expected behavior By following https://docs.statamic.com/knowledge-base/error-pages I should be able to see my custom error template.

Environment details:

jimblue commented 5 years ago

I'm not sure but it might related to: https://statamic.com/forum/3050-locales-tag-not-working-on-error-page

Apparently the error come from the {{ locale }} tag. Maybe it's because the 404 page doesn't seems to have a local variable?

In case it helps, here is the langswitcher.html partial where I use the {{ locale }} tag:

{{ locales }}

  {{ if locale:name != locale_name }}

    <a class="button" href="{{ url }}">{{ locale:name }</a>

  {{ /if }}

{{ /locales }}
jimblue commented 5 years ago

Also, I've notice that the {{ 404 }} tag is not working while using the custom template.

Thank you so much for your help! 😃

Cheers

jasonvarga commented 5 years ago

I can't reproduce this. Can you give any more details? What does your system.yaml look like?

Also, why are you trying to use the {{ 404 }} tag on your 404 template? You're already on a 404.

jimblue commented 5 years ago

I confirm the problem come from the {{ locales }} tag. When I remove it from my custom error template, it fix the problem.

Didn't you try to add the above snippet to a custom error template?

BTW, here is my system.yaml:

locales:
  en:
    name: en
    full: en_US
    url: 'https://statamic.test/'
  fr:
    full: fr_FR
    name: fr
    url: 'https://statamic.test/fr'
timezone: UTC
date_format: 'F jS, Y'
default_extension: md
filesystems:
  content:
    driver: local
    root: site/content
  storage:
    driver: local
    root: site/storage
  users:
    driver: local
    root: site/users
  themes:
    driver: local
    root: site/themes
    url: /site/themes
app_key: 6mXpUSPsbizeeM0ypnfetGVcn9e692zD
redactor:
  -
    name: Standard
    settings:
      buttons:
        - formatting
        - bold
        - italic
        - link
        - unorderedlist
        - orderedlist
        - html
  -
    name: Basic
    settings:
      buttons:
        - bold
        - italic
csrf_exclude:
  - '/!/Fetch/*'
  - /!/Charge/webhook
yaml_parser: symfony
send_powered_by_header: true
ensure_unique_ids: true
jasonvarga commented 5 years ago

Yes I tried your snippet. Try changing your french url to 'https://statamic.test/fr/'

jimblue commented 5 years ago

fixed! thank you so much 👍

jimblue commented 5 years ago

Sorry I've talk to fast and forgot to clear cache... Adding an ending slash didn't help...sadly

shabbarabbas commented 5 years ago

Anyone got solution for this , i tried all but still having issue

jimblue commented 5 years ago

Ok I've maybe found out. This bug happen if you don't have any global file named global.yaml. Can you that confirm guys?

jasonvarga commented 5 years ago

Confirmed.

I've fixed it, although, what are you expecting this tag to output on a page with no content?

jimblue commented 5 years ago

For translation feedback obviously 😄 ! Thank for the fix, I close this issue then.

jasonvarga commented 5 years ago

But if you are on a 404 page, what are you translating?

jimblue commented 5 years ago

The error message

jasonvarga commented 5 years ago

Where are you defining the error message?

monstromatic commented 5 years ago

Ok I've maybe found out. This bug happen if you don't have any global file named global.yaml. Can you that confirm guys?

I have the same issue. Did you put a new global.yaml in the 'settings' folder? What did you write in it to solve the problem? In your 'theming.yaml', is your var 'error_template_folder: /' ? Thanks for your help