Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions packages/cli-kit/src/public/node/liquid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,30 @@ import {joinPath, dirname, relativePath} from './path.js'
import {outputContent, outputToken, outputDebug} from './output.js'
import {Liquid} from 'liquidjs'

let _engine: Liquid | undefined

/**
* Returns a shared instance of the Liquid engine.
*
* @returns Liquid engine instance.
*/
function getEngine(): Liquid {
_engine ??= new Liquid()
return _engine
}

/**
* Renders a template using the Liquid template engine.
*
* @param templateContent - Template content.
* @param data - Data to feed the template engine.
* @returns Rendered template.
*/
export function renderLiquidTemplate(templateContent: string, data: object): Promise<string> {
const engine = new Liquid()
export async function renderLiquidTemplate(templateContent: string, data: object): Promise<string> {
if (!templateContent.includes('{{') && !templateContent.includes('{%')) {
return templateContent
}
const engine = getEngine()
return engine.render(engine.parse(templateContent), data)
}

Expand Down
Loading