How to use the handlebars.partials function in handlebars

To help you get started, we’ve selected a few handlebars examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nuysoft / Mock / test / nodeunit / mock4xtpl-node.js View on Github external
exports.test_string_sub_tpl = function(test) {
    var tpl4xtpl, data4xtpl, html4xtpl,
        tpl4hdb, data4hdb, html4hdb;

    XTemplate.addSubTpl('sub-tpl-1', '{{title}}')
    Handlebars.registerPartial("sub-tpl-1", '{{title}}');

    tpl4xtpl = '{{include "sub-tpl-1"}}'
    tpl4hdb = '{{> sub-tpl-1}}'
    // test.deepEqual(Handlebars.parse(tpl4xtpl), Handlebars.parse(tpl4hdb))
    // console.log(JSON.stringify(Mock4XTpl.parse(tpl4xtpl), null, 4));
    // console.log(JSON.stringify(Handlebars.parse(tpl4xtpl), null, 4));
    // console.log(JSON.stringify(Handlebars.parse(tpl4hdb), null, 4));

    data4xtpl = Mock4XTpl.mock(tpl4xtpl)
    data4hdb = Mock4XTpl.mock(tpl4xtpl, {}, Handlebars.helpers, Handlebars.partials)
    test.deepEqual(data4xtpl, data4hdb)
    // console.log(JSON.stringify(data4xtpl, null, 4))

    html4xtpl = new XTemplate(tpl4xtpl).render(data4xtpl)
    html4hdb = Handlebars.compile(tpl4hdb)(data4hdb)
    test.deepEqual(html4xtpl, html4hdb)
    // console.log(html)

    test.done()
}
github modularcode / modular-admin-html / tools / gulptask-html.js View on Github external
// const templateBody = frontMatter(file.contents.toString('utf8')).body;

  // console.log(templateBody);

  // Compile template without yaml headers
  const template = handlebars.compile(
    // templateBody
    String(file.contents).replace(/---(.|\n)*---/, '')
  );
  const templateRes = template(templateContext);

  // Layout processing
  const layout = context.layout || null;

  // If the layout exists, render it with template inside
  if (layout && partials[layout] && handlebars.partials[layout]) {

    // New vinyl file based on partail vinyl
    const layoutFile = new File(partials[layout]);
    const layoutContext = getTemplateContext(layoutFile);

    // Remove layout parameter from template context
    delete templateContext.layout;

    // Add body to context
    Object.assign(layoutContext, templateContext, {
      body: templateRes
    });

    // Call recursively render template again
    pageRes = renderTemplate(layoutFile, layoutContext);
  }
github modularcode / modular-admin-html / tools / gulptask-html.js View on Github external
// Result context
  const context = Object.assign({}, contextExternal, contextTemplate, contextInherited);

  // Page render result
  let pageRes = "";

  // Compile template
  const template = handlebars.compile(String(file.contents));
  const templateRes = template(context);

  // Layout processing
  const layout = context.layout || null;

  // If the layout exists, render it with template inside
  if (layout && partials[layout] && handlebars.partials[layout]) {

    // New instance of context
    let layoutData = Object.assign({}, context);

    // Add body to context
    layoutData = Object.assign(layoutData, {
      body: templateRes
    });

    // Remove layout parameter from inhereted context
    delete layoutData.layout;

    // New vinyl file based on partail vinyl
    const layoutFile = new File(partials[layout]);

    // Call recursively render template again
github cliqz-oss / browser-core / modules / offers-v2 / sources / content / app.es View on Github external
import { messageHandler, sendMessageToWindow } from 'offers-v2/content/data';
import $ from 'jquery';
import Handlebars from 'handlebars';
import templates from 'offers-v2/templates';

Handlebars.partials = templates;


// retrieves the current offer id from the document
function cqzOfferGetCurrentOfferID() {
  const offerIDElem = document.getElementById('cliqz-offers');
  if (!offerIDElem || offerIDElem.cliqzofferid === '') {
    return 'unknown';
  }
  return offerIDElem.cliqzofferid;
}

// receive buttons callback
function cqzOfferBtnClicked(ev) {
  // filter if it is button or not

  if (!ev.target || !ev.target.hasAttribute("data-cqz-of-btn-id")) {
github cliqz-oss / browser-core / modules / mobile-ui / sources / window.es View on Github external
init() {
    Object.keys(helpers).forEach(function (helperName) {
      Handlebars.registerHelper(helperName, helpers[helperName]);
    });
    window.CLIQZ.templates = Handlebars.templates = templates;
    Handlebars.partials = templates;
    Object.keys(VIEWS).forEach(view => UI.VIEWS[view] = new (VIEWS[view])() );


  	window.CLIQZ.UI = UI;
  	window.CLIQZ.UI.init();
  }
github janrain / raml-fleece / src / to-html.js View on Github external
handlebars.registerHelper('showCodeOrForm', function(data, options) {
  var ret;
  if (data.type === 'application/x-www-form-urlencoded') {
    ret = handlebars.partials.parameters({
      type: 'Form',
      params: data.params,
    });
  } else {
    ret = handlebars.helpers.showCode(
      data.example,
      {hash: {type: data.type}}
    );
  }
  return new handlebars.SafeString(ret);
});
handlebars.registerHelper('showCode', function(data, options) {
github thejohnfreeman / jfdoc / lib / utility / handlebars.js View on Github external
handlebars.loadPartial = function loadPartial(name) {
    var partial = handlebars.partials[name];
    if (typeof partial === "string") {
      partial = handlebars.compile(partial);
      handlebars.partials[name] = partial;
    }
    return partial;
  };
github helpers / handlebars-helpers / lib / helpers / layouts.js View on Github external
exports.extend = function(layout, options) {
  var context = Object.create(this || null);
  var template = Handlebars.partials[layout];

  if (typeof template === 'undefined') {
    throw new Error("Missing layout: '" + layout + "'");
  }

  if (typeof template === 'string') {
    template = Handlebars.compile(template);
  }

  if (typeof options.fn === 'function') {
    options.fn(context);
  }

  return template(context);
};
github future-architect / cheetah-grid / packages / docs / scripts / handlebars / helpers.js View on Github external
Handlebars.registerHelper('code', function(...args) {
		const arg = analyzeArguments(...args);
		const option = Object.assign({class: 'js'}, arg.hash);
		option.code = arg.get(this);
		let template;
		if (typeof Handlebars.partials.code !== 'function') {
			template = Handlebars.compile(Handlebars.partials.code);
		} else {
			template = Handlebars.partials.code;
		}

		return new Handlebars.SafeString(template(option));
	});
	Handlebars.registerHelper('json', function(...args) {
github cliqz-oss / browser-core / modules / dropdown / sources / dropdown.bundle.es View on Github external
import Results from './results';

let currentContextId;
if (chrome.omnibox2) {
  currentContextId = chrome.omnibox2.getContext();
}

let urlbarAttributes = {};
let currentQuery = '';
let previousResults;

const styleElement = document.createElement('style');
let lastNavbarColor = null;
document.head.appendChild(styleElement);

Handlebars.partials = templates;
Object.keys(helpers).forEach((helperName) => {
  Handlebars.registerHelper(helperName, helpers[helperName]);
});

const postMessage = (message) => {
  const searchParams = new URLSearchParams(window.location.search);
  const isCrossOrigin = searchParams.get('cross-origin') !== null;
  const target = isCrossOrigin ? window.parent : window;
  target.postMessage(message, '*');
};

const spanan = new Spanan(({ action, ...rest }) => {
  postMessage({
    ...rest,
    target: 'cliqz-renderer',
    action,