CSS and Freemaker

903 views
Skip to first unread message

Krasimir Cholakov

unread,
Jun 22, 2014, 2:07:38 PM6/22/14
to spar...@googlegroups.com
Hey Guys, 

I am currently playing with Spark + FreeMaker and I really enjoy it. I read for how to setup static files, but is there a way to refer to a css file located in a folder under my project directly? I mean like this:

<!DOCTYPE html>
<html>
  <head>
    <title>${title}</title>
    <link rel="stylesheet" type="text/css" href="css/default.css">
  </head>
  <body>
    ...
  </body>
</html>


Thank you.


Leonan Luppi

unread,
Jul 28, 2014, 7:24:37 AM7/28/14
to spar...@googlegroups.com
Set staticFile and call your css in template.

a platypus

unread,
Aug 21, 2014, 11:41:58 PM8/21/14
to spar...@googlegroups.com
Hi Krasimir,

I put my style sheets below my static content as follows:

  • staticFileLocation( "/web" );
/web/
  |-- index.html
  +-- styles/
        +
        +--- default.css
  
And the index.html

... <link href="styles/default.css" rel="stylesheet"   type="text/css" />

I also have other generated HTML pages as with freemarker.  They just collect the path:
  • /styles/default.css,  or
  • localhost:8081/styles/default.css
Shows the CSS way index gets it.

If you have a path in your code with "/styles", that will probably break it.  However that should work for most cases.

Kind regards,

   Will



On Monday, June 23, 2014 4:07:38 AM UTC+10, Krasimir Cholakov wrote:
Hey Guys, 


Krasimir Cholakov

unread,
Aug 27, 2014, 3:54:07 AM8/27/14
to spar...@googlegroups.com
Thanks a lot Will. I will try soon.

a platypus

unread,
Aug 27, 2014, 7:30:43 PM8/27/14
to spar...@googlegroups.com
You're welcome.

One update though.  If you want to test the CSS and Javascript "outside" the server, that needs to be done with CSS, JS files in a reachable directory.

What I did:
  • Put my Freemaker template with in the static pages for editing and checking styling, etc.
  • Copy template to the spark/templates/freemaker folder when I was happy with that

There ought to be a way to specify where the templates are sourced -- When I run freemaker in a plain Java app, freemaker accepts any legitimate URL.  Spark is setting a specific look-up path internally.  I don't agree that the current location is the right for sites when you need media, css, js and other resources to be accessible for the template during development as well as at run-time.

Moving files is an OK development pattern for me, because it means I've staged styling changes before I test the template in a running app.

Good luck,

   Will

Reply all
Reply to author
Forward
0 new messages