surm
surm

Reputation: 197

How to include external javascript and css files in .ftl file

I want to include certain js and css files from a server in the .ftl file.

I tried by giving <@resource.javascript file="http://servername..."> and <#include "http://servername..."> but none worked.

Upvotes: 1

Views: 7332

Answers (3)

Eddie Martinez
Eddie Martinez

Reputation: 13910

place the the stylesheet in the directory and use the <#include "/{path to style sheet}/Styles.css">

and make sure your style sheet is inside the styles element:

<style type="text/css">
...
</style>

Example using the previous approach:


Test Template

<html>
<head>
<#include "css/test.css">
</head>
<body>
bla bla bla
</body>
</html>

Test CSS

<style type="text/css">
body{background-color:#C5C5C0;}
*{font-family:Tahoma, Verdana, Helvetica, sans-serif;}
</style>

Upvotes: 2

Andrew Nepogoda
Andrew Nepogoda

Reputation: 1895

If you ussing Struts 2 you can include css files at this way:

<link rel="stylesheet" href="<@s.url value='path to your css file'/>" type="text/css" media="screen" />

Upvotes: 0

ddekany
ddekany

Reputation: 31152

I don't know what @resource is (it's something framework specific there), but #include is normally used for including local files, not a remote URL-s. FreeMarker runs on the server, so local path here means a path on the server. (It's easy to extend FreeMarker to support remote includes, but I guess you don't really want that.)

Upvotes: 0

Related Questions