JS and CSS partials
According to the new CSP (Content Security Policy) requirements, all inline css and js content will be blocked by browser.
Samples that would be blocked:
<p style="padding: 5px;">blocked</p>
<script>console.log("blocked")</script>
<header><stile>html {padding:5px;}</style></header>
<button onclick="funccall()">blocked</button>
Valid samples:
<header><link rel="stylesheet" href="{{ "partial-css" | staticFileLink }}"></header>
<header><link rel="stylesheet" href="https://link.to.my.css"></header>
<body><script src="{{ staticFileLink "partial-js" }}"></script></body>
To create a css/js partial, go to the template editor
and pick Create -> Create new template, then define name and select type JS or CSS respectively.
Editor will create empty file and append suffix -css
or -js
respectively to the
template name. Now we can write any valid css/js code there, just like we would do in regular
.js
or .css
files.
Now, when static partial is ready, we can link it with the page like this:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
{{/* Link css partial, as an option, calling linking function in a pipe */}}
<link rel="stylesheet" href="{{ "partial-css" | staticFileLink }}">
<title>Document</title>
</head>
<body>
{{/* Page content */}}
{{/* Link js partial, as an option, using regular linking function call */}}
<script src="{{ staticFileLink "partial-js" }}"></script>
</body>
</html>
Java-script and css partials are static files, and they are not part of the goerp template.
To link our templates with the static partials (js, css), we can use helper function staticFileLink
like this: <link rel="stylesheet" href="{{ "partial-css" | staticFileLink }}">
. Or make linking as
usual css and js imports: <link rel="stylesheet" href="https://link.to.css.file">