Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jade include with parameter

Tags:

pug

partial

In an older version of Jade I was able to include partials and pass variables into them like this: !=partial('partials/video', {title:video.title, artist:video.artist}) now the partial connotation does not exist any more. How do I achieve the same thing using the include connotations?

like image 600
suMi Avatar asked Jun 21 '16 05:06

suMi


People also ask

How do you access variables in pugs?

Inside your index. pug file, you then have access to the locals variable by way of its keys. The names of the variables in your Pug file become siteColors and siteNames . To set the entirety of an HTML element equal to a variable, use the equals operator = to do so.


1 Answers

You can use mixins for that. Wrap your include content inside a mixin and call the mixin function in your pug file. See my example below.

include-file.pug

mixin my-include(title, description)
  h1= title
  p= description

index.pug

include include-file
html
  head
  body
    +my-include('my title', 'my description')
like image 72
cglotr Avatar answered Nov 16 '22 20:11

cglotr