1

I have set up a Drupal 8 site with a custom home page using page--front.html.twig. The content displays at domain.com/front. When I go into Administration to change to the new home page, it says that the path is invalid. I've also tried leaving the field blank.

Path is invalid

I also noticed that when I'm on /front, the browser tab displays "Page not found".

I've cleared the cache repeatedly (and every time it sends me to /user/1).

What am I missing here?

2

There are two separate issues at play here, which is where you are getting confused.

1) page--front.html.twig - this is a template suggestion for the page theme hook. This can be seen by the double-hyphens that follow page. The page theme hook is used to wrap the content of every page on the site, using the page.html.twig template. Drupal's theme layer allows for creating suggestions for templates that take precedence over the base template. In this case, when on the front page, the site looks for page--front.html.twig, and if it finds this file, it uses it. You have created this file. However, you'll notice I said this template wraps the current page content. That leads to:

2) Page content. 'Pages' on Drupal show content if a page has been assigned to the given path. However, if a user goes to a path that doesn't exist, they get the 'page not found' page. This page is wrapped by page.html.twig, just like any content page.

When you go to /front, you see page not found, because you have not created a page at that path yet. You've only created a template for the front page, whatever that may be (even if that ends up being page not found).

You can test this by creating a new node, and setting the path to be /front (note - you'll need appropriate permissions for this). Then set the site front page to /front, and your template will be picked up.

| improve this answer | |
  • Ok, I get what you're saying. Thank you so much for clearing this up. – Chanel May 11 at 20:46
1

If you need a clear homepage, then you can use the Empty Page module. Just create a page with the module, add the URL to page in the Site Information settings and define a template in the theme.

| improve this answer | |

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.