How to use the twig.renderWithLayout function in twig

To help you get started, we’ve selected a few twig 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 namics / generator-nitro / packages / nitro-app / app / templating / twig / engine.js View on Github external
files[path.basename(file, '.js')] = `${projectHelpersDir}/${file}`;
	}
});

Object.keys(files).forEach((key) => {
	const helperTagFactory = require(files[key]);

	// expose helper as custom tag
	/* eslint-disable-next-line */
	Twig.extend(function(Twig) {
		Twig.exports.extendTag(helperTagFactory(Twig));
	});
});

// eslint-disable-next-line
Twig.renderWithLayout = (path, options, fn) => {
	const layoutPath = `${options.settings.views}/${options.layout}.${options.settings['view engine']}`;

	function layoutRendered(error, layout) {
		function bodyRendered(body) {
			layout = layout.replace('', body);
			return fn(null, layout);
		}
		return Twig.__express(path, options, bodyRendered);
	}
	return Twig.__express(layoutPath, options, layoutRendered);
};

module.exports = Twig;
github namics / generator-nitro / packages / project-nitro-twig / app / templating / twig / engine.js View on Github external
projectFiles.map((file) => {
	if (path.extname(file) === '.js') {
		files[path.basename(file, '.js')] = projectHelpersDir + file;
	}
});

Object.keys(files).forEach((key) => {
	const helperTagFactory = require(files[key]);

	// expose helper as custom tag
	Twig.extend(function(Twig) {
		Twig.exports.extendTag(helperTagFactory(Twig));
	});
});

Twig.renderWithLayout = function(path, options, fn) {
	const layoutPath = options.settings.views + '/' +  options.layout + '.' + options.settings['view engine'];

	function layoutRendered(error, layout) {
		function bodyRendered(error, body) {
			layout = layout.replace('', body);
			return fn(null, layout);
		}
		return Twig.__express(path, options, bodyRendered);
	}
	return Twig.__express(layoutPath, options, layoutRendered);
};

module.exports = Twig;