0

my question is how can i have custom folders in express

my situation is this, i want to have the logic that if i have an specific name in my database i want that my css and js paths change before they get rendered

on default my path in express is

app.use(express.static(path.join(__dirname, 'public')));

but if the user "spartan" gets called the main css path under public should change to /spartan/css/file.xyz

in this snipped from my handlebars template i've tried that

{{#each site.cssFiles}}
    <link rel="stylesheet" href="{{site.name}}/css/{{this}}.css" />
{{/each}}

on this example the result is

<link rel="stylesheet" href="/css/main.css">

but why? And how do i can get my target logic implementet?

1 Answers1

0

You need to exit the scope of the current handlebars block like this :

{{#each site.cssFiles}}
    <link rel="stylesheet" href="{{../site.name}}/css/{{this}}.css" />
{{/each}}

By doing so handlebars will render whichever you have provided as site.name from your res.render method.

drinchev
  • 19,201
  • 4
  • 67
  • 93