R
R
Roman Tatarinov2016-09-06 15:09:46
Pug
Roman Tatarinov, 2016-09-06 15:09:46

How to override class on every jade page?

there is a template that I extend on every page. I need to change the class of the body so that one page has "body.index" and the other has "body.secondary" and so on. Naturally, do not create your own template for each page. I tried through everything, interpolation, mixins, nothing helps. Nobody knows how to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
itsjustmypage, 2016-09-09
@romich

On each page:

extends /core/core.pug // подключаем шаблон

// создаём блок переменных, где объявляем наши переменные для страницы
block variables 
  - var pageClass = 'mainPage';		//- <body class="HERE">

In the template itself:
block variables // подключение блока переменных со страницы в самом начале

// код вашего шаблона
doctype html
html.no-js(lang= pageLang)

Note: in jade it worked only if the block of variables was first declared on the pages, and then the template was included. In pug, you can either way.
Instructions for blocks in pug: https://pugjs.org/language/inheritance.html
ps You can set the base path for pug when building in gallp, so it's easier to include the template on the pages.
gulp-pug( {basedir: *path*} );

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question