S
S
Stanislav2016-04-12 20:16:06
Node.js
Stanislav, 2016-04-12 20:16:06

How to load a template from a folder by category url in JADE?

I have about 30 categories and each category has its own html code structure, now in the template directory I use the elements.jade file, which in turn pulls the necessary template.
For example

if( ! catalog.url)
    .data Catalog not found
if(catalog.url = 'cat') 
    .data Тут вывод определенного текста и HTML кода принадлежащего каталогу cat
if(catalog.url = 'cat2') 
    .data Тут вывод определенного текста и HTML кода принадлежащего каталогу cat2

You can of course swiche, but not so important.
The thought slipped through, to create a directory in which to drop files from the category url and the necessary HTML code, for example.
./elements/cat.jade
./elements/cat2.jade

It would be very convenient for me to create such a structure, but how can I load these templates in a loop?
In index.jade for example
for(i; i < data.length;i++) {
    -var x = data[i];

    // тут какой то код

    // Тут надо подгрузить шаблон, что то вроде
    include ./elements/#{x.catalog.url} // понятно что не работает, но зато наглядно отражает что хочется сделать

    // тут тоже какой то код
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stanislav, 2016-04-19
@ms-dred

Found a solution.
On the backend

var jade  = require('jade');
.......
res.render('index', {templateRender: jade.renderFile});

in jade
!= templateRender('полный путь до файл' + template + '.jade', options)

K
Konstantin Kitmanov, 2016-04-12
@k12th

The last time I tried it was impossible. The parser simply treats what comes after the include as a static string, and that's it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question