12

How do I change the Drupal 8 frontpage template, so it doesn't use the regular page.html.twig template?

  • Hi! Welcome do DA. :) I took quite a few liberties with editing the question, I hope I still kept the core of it intact. Otherwise feel free to revert or edit again, but please try to keep the text short and to the point. Regarding answering your question, I don't know, but I notice that the views module has a views-view--frontpage.html.twig file. Following that patterns, it's possible that the the correct template name would be frontpage.html.twig. You might want to try. Other templates in core are named with a - separating their name from page, so perhaps front-page.html.twig? – Letharion Nov 7 '14 at 8:37
  • I added all those files to my templates folder in my theme and still it shows the page.html.twig instead of those i cleared the cache too before reloading the page. – Stefan Nov 7 '14 at 8:52
23

Enable twig_debug and you will see HTML comments surrounding the output that tell you what template suggestions are available. In this case you will get output like:

<!-- THEME DEBUG -->
<!-- THEME HOOK: 'page' -->
<!-- FILE NAME SUGGESTIONS:
   * page--front.html.twig
   * page--node.html.twig
   x page.html.twig
-->
<!-- BEGIN OUTPUT from 'core/modules/system/templates/page.html.twig' -->

Naming your template page--front.html.twig will use that template for only the homepage.

  • how does this work with subfolders? E.g. having a folder page in my templates directory. – ferdynator Sep 11 '15 at 10:51
  • @ferdynator it works just fine, you can add subfolders to organize your templates. – Cottser Sep 16 '15 at 19:32
  • 1
    This won't be picked up until you clear your caches, of course (said the newbie)! – Deborah Nov 23 '16 at 8:52

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.