-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Current behavior
const template = `
<meta name="description" content="{META_DESCRIPTION}">
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-112910279-1');
</script>
`
const tokens = { META_DESCRIPTION: 'This is a website about dogs' }
const rendered = renderTemplate(template, tokens)rendrered would then be:
<meta name="description" content="This is a website about dogs">
<script>
window.dataLayer = window.dataLayer || [];
function gtag()undefined
gtag('js', new Date());
gtag('config', 'UA-112910279-1');
</script>Note: undefined where function block should be is undesirable.
Desired behavior
Add an options parameter with a single option key: tokenDelimeter. Possible values are module constants SINGLE_CURLY (default) and DOUBLE_CURYLY.
Then we can do this:
import renderTemplate, { DOUBLE_CURLY } from 'react-text-templates'
const template = `
<meta name="description" content="{{META_DESCRIPTION}}">
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-112910279-1');
</script>
`
const tokens = { META_DESCRIPTION: 'This is a website about dogs' }
const rendered = renderTemplate(template, tokens, { tokenDelimiter: DOUBLE_CURLY })edwardofclt
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request