templates - Alternative to Dynamic Includes In Jade -


what alternative solution trying use dynamic includes using express + jade? here i'm trying following setup:

  • routes
    • index.js
    • widgets.js
  • views
    • widgets
      • widget1.jade
    • index.jade
    • widget.jade
  • app.js

in app.js, specify following route:

app.get('/widgets/:widget', widgets.widgets);

in widgets route, widgets.js have:

exports.widgets = function(req, res){res.render('widgets/' + req.params.widget);};

this gives me ability view widget on own browsing /widgets/widget1. works great. can include widget in view this

include widgets/widget1 

this works great too. however, want add widget2 , want show widget1 , show widget2 within page. had hoped pass variablewidgetname view , reference this:

include widgets/#{variablewidgetname} 

this fails. when try access page, 500 error stating no such file or directory views\widgets#{variablewidgetname}.jade exists. cannot reference variables includes.

what other options have. if limitation in jade, there different approach should using? i've thought of loading widget via ajax hoped better solution using jade or express.

does know of better way this?

try using partial instead of include.

here works me (i use harpjs.com jade, uses "jade": "0.35.0"):

- var name = "something" != partial('./'+name+'/hello.md')`


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -