Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass a variable when using pug extends

I have a settings page called posting.pug and it extends a pug settingsLayout template. Where are several settings pages in my app. And I want to pass a variable posting=1 to the settingsLayout page to show a user that the posting page is the current.

How should I pass a variable to the template I extend?

I tried to set a variable before extends. That's not allowed.

I tried passing it as an attribute -- doesn't work.

like image 346
Dmitry Kaigorodov Avatar asked Mar 27 '26 16:03

Dmitry Kaigorodov


1 Answers

You can try like this

settingsLayout.pug

block variables    

doctype html
html
  head
  body
    // Try to call variable here
    h1 posting

posting.pug

extends settingsLayout

block variables
  - var posting = 1

I hope this work!

like image 169
Ha Huu Tin Avatar answered Apr 02 '26 05:04

Ha Huu Tin