Question

I am learning the very basics of web-developing with Clojure, but cannot seem to get my css to work using hiccup. I have tested several possible paths to the file, tried setting the link manually using tags, and even tried adding an html5, line at the top of the .css file. Nothing seems to be working. I am sure there is an idiomatic way to do it, that I just don't know. If someone could tell me how to use hiccup and css together so that it is guaranteed to work, I would be very grateful.

I have this tree structure for my directory:

.____resources
| |____public
|  |____404.html
|  |____500.html
|  |____home.css <- I want to see this augmenting the html5 in home from the landing.clj, below.
|____src
 |____clojuregrade
  |____landing.clj <- home function with html5 is here.
  |____web.clj

I have this function in landing.clj above:

(defn home [& [weights grades error]]
  (html5
    [:head
    [:title ...]
     (include-css "/public/home.css")] ;; <- Is this right?
    [:body
   (form-to [:post "/"]
     (text-area ...)]
     (text-area ...)]
     (submit-button "process"))]))

I have this code from home.css, above:

body {
    background-color: #BAC4E8;
}

h1 {
    font-family: Garamond;
    color: #29507A;

}

note: I have abridged the above code to try and generalize the question to make it useful for future users.

Was it helpful?

Solution

No you do not need to prefix it with public, either /home.css or home.css should be enough. If you are using Compojure note that you need to expose your resources explicitly (check: https://stackoverflow.com/a/7820392/206020).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top