How to use the liquidjs.Liquid function in liquidjs

To help you get started, weโ€™ve selected a few liquidjs 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 xpack / xpm-js / lib / xpm / init.js View on Github external
author.name = gitConfig.user.name
      }
      if (gitConfig.user && gitConfig.user.email) {
        author.email = gitConfig.user.email
      }
    }
    liquidMap.author = author

    const currentTime = new Date()
    liquidMap.year = currentTime.getFullYear().toString()

    const templatesPath = path.resolve(this.rootAbsolutePath,
      'assets', 'sources')
    log.debug(`from='${templatesPath}'`)

    this.engine = new Liquid({
      root: templatesPath,
      cache: false,
      strict_filters: true, // default: false
      strict_variables: true, // default: false
      trim_right: false, // default: false
      trim_left: false // default: false
    })

    log.info(`Creating project '${liquidMap.projectName}'...`)

    await this.render('package.json.liquid', 'package.json', liquidMap)

    try {
      const readmePath = path.resolve(config.cwd, 'LICENSE')
      await fsPromises.access(readmePath)
github harttle / liquidjs / demo / express / app.js View on Github external
const express = require('express')
const { Liquid } = require('liquidjs')

const app = express()
const engine = new Liquid({
  root: __dirname, // for layouts and partials
  extname: '.liquid'
})

app.engine('liquid', engine.express()) // register liquid engine
app.set('views', ['./partials', './views']) // specify the views directory
app.set('view engine', 'liquid') // set to default

app.get('/', function (req, res) {
  const todos = ['fork and clone', 'make it better', 'make a pull request']
  res.render('todolist', {
    todos: todos,
    title: 'Welcome to liquidjs!'
  })
})
github BuilderIO / builder / packages / shopify / js / index.ts View on Github external
import { Context, Liquid as LLiquid } from 'liquidjs';

const liquid = new LLiquid();

liquid.registerFilter('money', value => {
  const str = String(value);
  // TODO: locales
  return '$' + str.slice(0, -2) + '.' + str.slice(-2);
});

const tempNoopFilters = ['img_url', 't'];
for (const tempNoopFilter of tempNoopFilters) {
  liquid.registerFilter(tempNoopFilter, value => value);
}

interface State {
  [key: string]: any;
}
github harttle / liquidjs / demo / nodejs / index.js View on Github external
const { Liquid } = require('liquidjs')

const engine = new Liquid({
  root: __dirname,
  extname: '.liquid'
})

engine.registerTag('header', {
  parse: function (token) {
    const [key, val] = token.args.split(':')
    this[key] = val
  },
  render: async function (scope, hash, emitter) {
    const title = await this.liquid.evalValue(this.content, scope)
    emitter.write(`<h1>${title}</h1>`)
  }
})

const ctx = {
github harttle / liquidjs / demo / typescript / index.ts View on Github external
import { Liquid, TagToken, Hash, Context, Emitter } from 'liquidjs'

const engine = new Liquid({
  root: __dirname,
  extname: '.liquid'
})

engine.registerTag('header', {
  parse: function (token: TagToken) {
    const [key, val] = token.args.split(':')
    this[key] = val
  },
  render: async function (context: Context, hash: Hash, emitter: Emitter) {
    const title = await this.liquid.evalValue(this['content'], context)
    emitter.write(`<h1>${title}</h1>`)
  }
})

const ctx = {
github Azure / api-management-developer-portal / src / services / templatingService.ts View on Github external
public static async render(template: string, model: Object): Promise {
        const engine = new Liquid();
        const result = await engine.parseAndRender(template, model, null);

        return result;
    }
}
github aiden / rpc_ts / src / site / index.ts View on Github external
async function generateTypeDocTemplates() {
  const engine = new Liquid({
    root: path.resolve(__dirname, '../../site'),
    extname: '.html',
  });

  const navbar = await engine.renderFile('common/partials/navbar.html', {
    page: { url: 'typedoc' },
  });
  fs.writeFileSync('site/typedoc/typedoc_theme/partials/header.hbs', navbar);

  const analytics = await engine.renderFile('common/partials/analytics.html');
  fs.writeFileSync(
    'site/typedoc/typedoc_theme/partials/analytics.hbs',
    analytics,
  );
}

liquidjs

A simple, expressive and safe Shopify / Github Pages compatible template engine in pure JavaScript.

MIT
Latest version published 2 days ago

Package Health Score

86 / 100
Full package analysis

Popular liquidjs functions