Closed johnmathews closed 4 years ago
Is it feasible to use pypugjs to convert the pug template to jinja, and then use django's jinja backend? I'm trying this now, but am having trouble with relative/absolute file paths for the include
statements.
Thats the way it works anyway .. pypugjs ist just producing the jinja input, which is then replacing variables. But in general mixins are supported: https://github.com/kakulukia/pypugjs#notable-features How are you trying to use em?
And it still works.
How are you trying to use mixins?
include statements with paths that were relative to the files wouldn't work.
e.g.: ../bar.pug
doesn't work
i got it to kind of work by making all include
statements contain file paths relative to the template dir specified in django's settings.py.
e.g.: templates/foo/bar.pug
Also, i needed to list all the mixin arguments on one line: this doesn't work:
+myMixin({
var1: 'anything',
var2: 'something else',
})
but this does work
+myMixin({ var1: 'anything', var2: 'something else', })
however i think its going to be simpler to use DRF and render the pug templates client side.
include statements with paths that were relative to the files wouldn't work. e.g.:
../bar.pug
doesn't work
This might be a pug feature, but since pypugjs reuses Django's template loaders, you have to add any additional mixin dirs to the template directories to be able to include em that way.
Also, i needed to list all the mixin arguments on one line: this doesn't work:
+myMixin({ var1: 'anything', var2: 'something else', })
but this does work
+myMixin({ var1: 'anything', var2: 'something else', })
This looks weird. Jinja uses double curly braces and your example looks like the javascript version. Since pypugjs is just translating pug to html and then feeding it to Jinja for variable replacement, i fear what you are trying to do is just not possible with pypugjs. :(
Anyway for anything more complex in the frontend my recommendation is to use VueJS rather than creating complex templates in Django. So yes, DRF would be the way to go .. or GraphQL.
Is mixin block support planned? If not, is there a workaround?
Description
I have some pug templates with the following mixin syntax:
which gives the following error:
unexpected token "attrs" in file sb-ui-kit-pro/src/pug/pages/index.pug on line 18
If I reformat the mixin block to the following (so that the mixin is all on one line):
then I get the following error:
The mixin blocks are not supported yet.
Traceback: