V
V
Vadim Somov2017-09-21 01:44:54
JavaScript
Vadim Somov, 2017-09-21 01:44:54

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")

And this is the file where the block should be called
//-  _head.pug
extends ../blocks/_metas.pug

<!DOCTYPE html>
html(lang="ru")
    head
        block metas
    body hello world

file from which html should be compiled
//- index.pug
include parts/_head.pug

Am I actually doing it right?
Here is a screenshot for your convenience

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Bobylev, 2017-09-21
@dpigo

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.


From the tracker :
GOOD:
extends ./layout.pug

block content
  div some content

BAD:
extends ./layout.pug

block content
div this content isn't inside a block

Similar questions

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question