This repository has been archived on 2023-03-18. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
osr-discourse-src/app/assets/javascripts/discourse/helpers/custom-html.js.es6
T

27 lines
699 B
JavaScript

import { registerHelper } from 'discourse-common/lib/helpers';
import PreloadStore from 'preload-store';
const _customizations = {};
export function getCustomHTML(key) {
const c = _customizations[key];
if (c) {
return new Handlebars.SafeString(c);
}
const html = PreloadStore.get("customHTML");
if (html && html[key] && html[key].length) {
return new Handlebars.SafeString(html[key]);
}
}
// Set a fragment of HTML by key. It can then be looked up with `getCustomHTML(key)`.
export function setCustomHTML(key, html) {
_customizations[key] = html;
}
registerHelper('custom-html', function(params) {
const html = getCustomHTML(params[0]);
if (html) { return html; }
});