Thymeleaf: how to include javascript file (
contents of this file) and wrap content this file with CDATA block
My js file is like this:
this is javascript file and have &&, I cannot edit this file
In my thymeleaf template I have:
<script th:include="http://address-to-file/myfile.js"></script>
I want to include this file, but I have error:
org.xml.sax.SAXParseException: The entity name must immediately follow the '&' in the entity reference.
How i can wrap this include file to CDATA block? In my template I achieve this result:
/*<![CDATA[*/
this is javascript file and have &&, I cannot edit this file
/*]]>*/
You can use th:src like this:
<script th:src="#{//address-to-your-file/yourfile.js";}"></script>
…which will render unmodified (except for URL rewriting), like:
<script src="address-to-your-file/yourfile.js"></script>
Related
Trying to go through the "openlayers-workshop" on Windows 8. In the "Basic - Creating a Map" section following the instructions and making the example map.html file. When viewing the html file in my browser the following error occurs:
ReferenceError: ol is not defined
Sourcefile: http://localhost:4000/map.html
Line: 18
I have followed the tutorial as far and installed the required prerequisites.
Is there something I haven't installed yet to make it work?
Any other Windows users out there that have the same problem?
Go to http://openlayers.org/download/ and download latest *dist.zip file. Extract this file. In the extracted folder there will be 3 files, you only need ol.js and ol.css. In the directory you have map.html create 2 folders, one called "css" and another called "js". In the "css" folder placer the ol.css file from the extracted folder. In the "js" folder placer the ol.js file from the extracted folder. In your map.html file change the line on line 4(may be different, you should see a line),
<link rel="stylesheet" href="/ol.css" type="text/css">
Change this to
<link rel="stylesheet" href="css/ol.css" type="text/css">
Similarly on line 12 of the map.html file change
<script src="/loader.js" type="text/javascript"></script>
To
<script src="js/ol.js" type="text/javascript"></script>
Now save and reload the map.html file, now it should display correctly. The reason you where original getting a error was because you hadn't included the openlayers library in your map.html file correctly.
I've included the following line in the BundleConfig.cs file:
bundles.Add(new ScriptBundle("~/bundles/jqueryajax").Include(
"~/Scripts/jquery.unobtrusive-ajax.min.js"));
However when I try to render it among other scripts, it's skipped.
Here is how I render the scripts:
#Scripts.Render(
"~/bundles/jquery",
"~/bundles/jqueryui",
"~/bundles/jqueryajax",
"~/bundles/jquerytree")
This is the output HTML, the jqueryajax bundle is omitted:
<script src="/Scripts/jquery-1.9.1.js"></script>
<script src="/Scripts/jquery-ui-1.10.2.js"></script>
<script src="/Scripts/jquery.jstree.js"></script>
I believe ScriptBundle tries to minify the file when debug="false" instead of using the existing .min.js file. There is a setting in web.config to affect how this works (set usePreMinifiedFiles to true):
<core enableTracing="false" ...>
<js defaultMinifier="EdwardsJsMinifier" usePreMinifiedFiles="true">
I have few questions on partials and overriding templates.
For that i used the following folder structure.
projectRoot
dust-core-0.6.0.min.js
jquery.js
test.html
partial.tl
main_without_override.tl
The content of partial.tl:
{+greeting} Hola {/greeting}
{+world} World {/world}
The content of main_without_override.tl:
{>partial/}
The content of test.html:
<!DOCTYPE html>
<html>
<head>
<script src="dust-core-0.6.0.min.js" type="text/javascript"></script>
<script src="jq.js" type="text/javascript"></script>
</head>
<body>
</body>
<script>
$.get('main_without_override.tl', function(){
console.log(arguments);
})
</script>
</html>
In the index.html when i try to get the main_without_override.tl its saying 404. But im sure that the file is there. The path that firebug is showing is correct.But browser says 404.
I want to know
How to get this main_without_override.tl
Apply templating for main_without_override.tl and render in the browser.
I searched in google most of the examples give only the syntax. Can somebody help me in rendering the main_without_override.tl template.
In order to compile templates on the client (which is probably not a really good idea), you need to include dust-full instead of dust-core. This is because dust-core does not include the Dust compiler.
The reason that compiling templates on the client is probably not a good idea is that Dust compiles to JavaScript and as #monshi mentioned, you can compile the templates and then serve them as JavaScript. It is possible to get .tl files through AJAX if you include dust-full, but it is a better idea to compile that template beforehand and then make a dynamic request for that .js file when you need.
You can include your dust template as a JavaScript file by using <script> tag, but you need to compile it first, which is explained here
Then add following templates (scripts) to test.html:
<script type="text/javascript" src="partial.js"></script>
<script type="text/javascript" src="main_without_override.js"></script>
And in you JavaScript render the template by dust.render method:
dust.render('main_without_override', your_json_object, function(err, out){
your_dom_element.innerHTML = out;
});
Related question:
how to use dustjs-linkedin as client side templating?
Is it possible to access
grails.app.context
from within a javascript library? --That is, not javascript inserted in a GSP file.
I have som javascripts that are context dependent, why I need to be able to access this from javascript.
I include the javascript in my gsp-files with:
<r:require modules="myModule" />
You can pass it to Javascript as global JS variable, put this inside <head> tag:
<g:javascript>
window.appContext = '${request.contextPath}';
</g:javascript>
and use it anywhere from plain javascript, like:
$.ajax({
url: appContext + '/hello/world'
})
Is there a plugin or how do I to change style sheet links on a certain web pages that is parsed by Glype?
I need to change the look and the colors of a remote hosted application to match my website theme.
OK, I found the way to do it. Steps:
Create a plugin file in the plugin folder of Glype.
The plugin file name should be the same as the domain you are trying to edit.
Use the preParse function to do a regular expression replacement of stylesheet URLs.
function preParse($input, $type) {
# Fix thumbnail images
$input = preg_replace(
'<link href="Url_One" type="text/css" rel="stylesheet" />',
'link href="Url_Two" type="text/css" rel="stylesheet" /',
$input);
return $input;
}