Monday 15 July 2013

clojure - CSS fails with extended paths in Compojure / Hiccup -


I am converting some noir websites to Composer.

I have a function that creates the layout of the page:

  (defn layout [title and content] (html5 [: head [: title "My Site | "Title" (included- css "css / main.css") [: body [: title [: h1 (link-to "/" "my site")]] content]))   

and this function and route are:

  (defn home-page [] (layout "home" [: div [: p] "home page"]]))) (f) -Roots ("/" [] [Home page] ("/") ("Articles" [] (Layout "Article List" [: div [: p "Article List"]])) Listings "[] (Article-list))   

When I visited Localhos T opens am: 3000 / article-list of all CSS rules work fine.

However, when I try to increase the URL path and change the program:

  (defn article-list [] (layout "article list" [: div [: P] "Article List"] F-Roots (Get "/" [] (Home-page)) () "(Get" Articles "" / Article List "[] (Article List) ( "/ Article-list / article-one" get [] (article-one))   

and go to localhost: 3000 / article-list / article-one, I get all the HTML But CSS rules do not work now when I inspect the page I do not have any style on the page on the CSS path & gt; head & gt; element.

I have searched for this issue, but there is no writing on it. I tried to drag the routes so that I could have:

  (defroutes article-routes ("/ paragraph-list / article-one" [] (article-a)) ((article Get the "/" [] (home page) (get "article-list" [] article-route) ("/ article" [] (article-list) ( / Pre> 

But my wages L Can I have the same problem I work on pages with extended path to CSS rules?

Your CSS is being included with a relative path, which means that when you Localhost: 3000 / article-list / article-one , then your browser is looking for CSS localhost: 3000 / article-list / css / main css .

The easiest way to fix this will be to css the (inclusion-css "/" CSS / main CSS "). / This will ensure that it always searches for localhost: 3000 / css / main.css .

No comments:

Post a Comment