0

I have such a directory content

app\
  app.js
html-views\
  corporate\
    css\main.css            //css.corp
    index.html
  ecommerce\
    css\main.css            //css.ecom
    index.html

I`m trying to config two routes:

var sys = require( "sys" );
var express = require("express");
var cons = require("consolidate");
var app = express();
app.engine("html",cons.swig);
app.set("view engine","html");
app.set("views","../html-views/");

//HERE I HAVE TO CONFIGURE CSS

app.get("/corporate",function(request,response){
response.render("corporate/index");
});
app.get("/ecommerce",function(request,response){
response.render("ecommerce/index");
});
app.listen(8080);

I want to configure choosing "main.css" depending to the route, but i can`t

If I write:

app.use("/css",express.static("../html-views/corporate/css"));
app.use("/css",express.static("../html-views/ecommerce/css"));

then one css will override another.

If I write:

app.get("/corporate",function(request,response){
    app.use("/css",express.static("../html-views/corporate/css"));
    response.render("corporate/index");
});

then they override each other only once.

How should I write? Thanks for your attantion.

4
  • Can you not have 2x app.js? Commented Feb 10, 2014 at 14:39
  • 2
    What about prefixing your /css in the two app.use()s with /corporate and /ecommerce? No more conflicts. Commented Feb 10, 2014 at 14:42
  • trying to do without changing .html (where src="css/main.css") Commented Feb 10, 2014 at 18:53
  • Connect vhosts might be what you are after senchalabs.org/connect/vhost.html Commented Feb 10, 2014 at 21:18

2 Answers 2

2

I tried to solve the same issue as following:

In the ecommerce.html,I include the css file for this template like this:

<link rel="stylesheet" href="./stylesheets/ecommerce.css">

So in this way, different routes include different css for specific template.

Hope this will you help you.

Cheers

Sign up to request clarification or add additional context in comments.

Comments

0

Is there any reason that you don't use template engine? Handlebars with layout option can solve this easily.

I found answer here https://stackoverflow.com/a/8790999/1822805

3 Comments

For now the question is a bit outdated) I guess, your solution can work.
app.get("/corporate",function(request,response){ response.render("/index",{cssOption:'corporate'}); });
Lol I did not check the date. Glad to know you! ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.