@AleksKek
учусь веб-разработке

Как исправить ошибку в pug c блоками?

Всем привет. никак не могу разобраться в pug. При компиляции возникает ошибка "Only named blocks and mixins can appear at the top level of an extending template".

Это файл блока для мета тегов
//- _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


файл из которого должен компилироваться html
//- index.pug
include parts/_head.pug

Вообще правильно ли я делаю ?
Вот скриншот для удобства
  • Вопрос задан
  • 2388 просмотров
Пригласить эксперта
Ответы на вопрос 1
dpigo
@dpigo
Front-end developer
Если не до конца понимаете как работают шаблоны с наследованием, используйте простые инклюды.

Из документации:
Common mistakes

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.


Из треккера:
If your template has extends in it, it can only have other content inside blocks.


GOOD:

extends ./layout.pug

block content
  div some content


BAD:
extends ./layout.pug

block content
div this content isn't inside a block
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы