How to use use tokens in Sitecore SXA metadata partial design? - sitecore

I use a HTML snippet in the Sitecore SXA metadata partial design to add some links in the head of the resulting HTML:
This HTML is:
<link rel="stylesheet" href="https://unpkg.com/sxa-umbrella-webcomponents#0.0.1/dist/sxa-umbrella-webcomponents/sxa-umbrella-webcomponents.css" />
<script type="module" src="https://unpkg.com/sxa-umbrella-webcomponents#0.0.1/dist/sxa-umbrella-webcomponents/sxa-umbrella-webcomponents.esm.js"></script>
<script nomodule src="https://unpkg.com/sxa-umbrella-webcomponents#0.0.1/dist/sxa-umbrella-webcomponents/sxa-umbrella-webcomponents.js"></script>
But I would like to have the base path configurable using for example a token, like:
<link rel="stylesheet" href="$WebComponentsBasePath/sxa-umbrella-webcomponents.css" />
<script type="module" src="$WebComponentsBasePath/sxa-umbrella-webcomponents.esm.js"></script>
<script nomodule src="$WebComponentsBasePath/sxa-umbrella-webcomponents.js"></script>
where the token is set to: "https://unpkg.com/sxa-umbrella-webcomponents#0.0.1/dist/sxa-umbrella-webcomponents.
But token replacement does not work in the HTML snippet.
Any idea on how to make this base path configurable for the metadata partial design so I can have different configuration for my development environment and the production environment, and have the possibility to easily switch the base path on production to roll forward a version or roll back a version of the files used based on a configured base path?

Related

How to locate websocketbridge.js in Django using channels websocket?

I am trying to implement websockets using channels in Django project. I am getting 404 for webscoketbridge.js Below is html template.
{% load staticfiles %}
{% block title %}Delivery{% endblock %}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<link href='https://fonts.googleapis.com/css?family=Satisfy' rel='stylesheet' type='text/css'>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="{% static 'channels/js/websocketbridge.js' %}" type="text/javascript"></script>
Also, I tried to have a look in the virtualenv/lib/python3.5/site-packages/channels path, there is no js folder or any file named websocketbridge.js
Has anyone solved this issue?
The javascript bridge was removed in v2.1.4. Here's the commit: https://github.com/django/channels/commit/2a9d764ad03927581aa2bfcadccc3e953949cb98#diff-b582cbb2f8294afa8bbe26c4c360a01d
This bit me, in my book that breaks semantic versioning.
As #tobyspark said, the javascript wrapper has been completely removed in the Django-channels 2. You can read more on how the js WebSocket wrapper was working in channels 1 here.
the simplest workaround to clear that error in your browser is to create a file called websocketbridge.js in the path shown in the error, "static/channels/js/", or you can specify any other path in your HTML src attribute matching the location of the static files and then add the code from here.
But you have to find a better implementation. You can use ReconnectingWebSocket. In the channels 2 release documentation, it is stated there might be other third-party packages for the binding but I don't know any other.

Angular-CLI - how to append a prefix to script tag on index.html

Angular-cli is generating the index.html file during ng-build.
The app runs on a hardware proxy, meaning that all of it's script tags need to be prefixed with "/some/prefix/". The cli generates the following script tags.
<script type="text/javascript" src="inline.js"></script>
<script type="text/javascript" src="styles.b1a79a362dfcae386d67.bundle.js"></script>
<script type="text/javascript" src="main.2b9bcc2dcbe5c9cb526b.bundle.js"></script>
Is there a way to prefix the src of each tag with something?
You need to set --base-href when serving or building, e.g. ng serve --base-href '/some/prefix/' --aot.
--base-href sets the <base href='/some/prefix'> tag in your HTML file and adds such prefix to all scripts and stylesheets that are automatically defined.
Note, however, that setting the base tag manually will not have the same effect and that will be overwritten every time you build your application.

Rails 4 - Vendor Asset Pipeline

I searched on google but only found subject on rails 3, and documentation of the rails 4 saw that project/vendor/assets is not recommended.
my html page will use many plugins, and are separated by folders, and within each folder has .js, .css, .png
will be impossible to separate each file (js, css, ...) of each plugin put into their respective folders: app/assets/javascripts, app/assets/stylesheets ...
How do I create a folder app/assets/vendor and map all the way plugins as they are today in my html template?
How do I import them in my html?
In pure html I do so today (example):
<link rel='stylesheet' type='text/css' href='assets/plugins/codeprettifier/prettify.css' />
<link rel='stylesheet' type='text/css' href='assets/plugins/form-toggle/toggles.css' />
<script type='text/javascript' src='assets/plugins/charts-flot/jquery.flot.resize.min.js'></script>
<script type='text/javascript' src='assets/plugins/charts-flot/jquery.flot.orderBars.min.js'></script>
I created a plugins folder within the assets, like this:
assets/plugins/form-toggle/toggles.css
assets/plugins/form-toggle/toggles.min.js
in assets/javascripts/application.js file I added:
//= require toggle.min
in assets/stylesheets/application.css file I added:
//= require 'toggles'

Go language strange behavior by handling templates

gotemplates
Hello!
I'm learning Go language now and trying to port some simple WEB code (Laravel 4).
Everything was well, until I tried to reproduce Blade templates into text templates.
I found that Go can load my CSS and JavaScript files only from the catalog with a name "bootstrap" only.
Here is my catalog tree which I tried to use:
start-catalog
bootstrap (link to bootstrap-3.3.1)
bootstrap-3.3.1
css
bootstrap.min.css
js
bootstrap.min.js
jquery
jquery (link to jquery-2.1.1.min.js)
jsquery-2.1.1.min.js
go_prg.go
Here are my templates:
base_js.tmpl
{{define "base_js"}}
{{template "login_1"}}
<script src = "/bootstrap/js/jquery"></script>
<script src = "/bootstrap/js/bootstrap.min.js"></script>
{{end}}
base_header.tmpl
{{define "base_header"}}
<head>
<title>PAGE TITLE</title>
<meta name = "viewport" content = "width=device-width, initial-scale=1.0">
<meta charset="utf-8">
<link href = "/bootstrap/css/bootstrap.min.css" rel = "stylesheet">
</head>
{{end}}
If the catalog name differs from "bootstrap" Go language or Firefox can't load files from the templates above: bootstrap.min.css, bootstrap.min.js, jquery.
If I use not the link but the catalog name directly "bootstrap-3.3.1" than Go or Firefox can't load.
If all required files are moved under "bootstrap" I'm getting the results I expected (exactly the same as in Laravel 4).
To launch go language code the command go run go_prg.go was used.
Environment: Ubuntu 14.04, go-1.3.3, Firefox 31.
Who's wrong: Go language, Firefox or me?
Any help will be highly appreciated!
The problem described was caused by
http.Handle("/bootstrap/", http.StripPrefix("/bootstrap/", http.FileServer(http.Dir("bootstrap"))))
before any template was handled. It allowed access files under the directory 'bootstrap' only.
The problem was fixed by changing to
http.Handle( , http.StripPrefix(, http.FileServer(http.Dir("."))))
and adding to pathes for CSS and JavaScript files. Like so
/bootstrap/js/jquery">.

Get the absolute static file URL in my Django template

I want to know how can I get the absolute URL of my static file directly in my template in Django ?
For now in my template :
<link rel="stylesheet" href="{% static "css/bootstrap.min.css" %}">
return
<link rel="stylesheet" href="/static/css/bootstrap.min.css">
How can I get on dev:
<link rel="stylesheet" href="http://127.0.0.1:8000/static/css/bootstrap.min.css">
on production
<link rel="stylesheet" href="https://mycompany.com/static/css/bootstrap.min.css">
There are two options:
recommended: use the sites framework to render the appropriate domain
not recommended: store your current domain as a Django setting in the settings file you use depending on your environment
I usually go for (1), the only downside being that you have to update the current domain in the DB, but that usually happens just once per deployment.
Then the appropriate domain will be displayed irrelevant of where code is running; you should always use the static tag in your template, rather than handling the display of the domain manually.