Answer the question
In order to leave comments, you need to log in
How to fix error in pug with blocks?
Hello. I can't figure out pug. Compiling error "Only named blocks and mixins can appear at the top level of an extending template".
This is a block file for meta tags
//- _metas.pug
block metas
title страница
meta(charset="UTF-8")
meta(name="viewport", content="width=device-width, initial-scale=1, user-scalable=no")
meta(name="description", content="Page description")
meta(name="keywords", content="page, keywords")
meta(name="theme-color", content="#000000")
meta(name="copyright", content="Author")
meta(name="apple-mobile-web-app-capable", content="yes")
meta(name="apple-mobile-web-app-status-bar-style", content="#000000")
meta(name="apple-mobile-web-app-title", content="Application Name")
meta(name="msapplication-TileImage", content="img/icon/144x144.png")
meta(name="msapplication-TileColor", content="#000000")
//- _head.pug
extends ../blocks/_metas.pug
<!DOCTYPE html>
html(lang="ru")
head
block metas
body hello world
//- index.pug
include parts/_head.pug
Answer the question
In order to leave comments, you need to log in
If you do not fully understand how templates with inheritance work, use simple includes.
From documentation:
Pug’s template inheritance is a powerful feature that allows you to split complex page template structures into smaller, simpler files. However, if you chain many, many templates together, you can make things a lot more complicated for yourself.
Note that only named blocks and mixin definitions can appear at the top (unindented) level of a child template. This is important! Parent templates define a page’s overall structure, and child templates can only append, prepend, or replace specific blocks of markup and logic. If a child template tried to add content outside of a block, Pug would have no way of knowing where to put it in the final page.
extends ./layout.pug
block content
div some content
extends ./layout.pug
block content
div this content isn't inside a block
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question