tmpl icon indicating copy to clipboard operation
tmpl copied to clipboard

Problem with backslash

Open janober opened this issue 5 years ago • 2 comments

First, thanks for the great library! Made my life much easier and is working great.

I did however run recently into one issue. It is illustrated here:

const tmpl = require('riot-tmpl');
tmpl.brackets.set('{{ }}');
tmpl.tmpl('C:\\User\\{{name}}.txt', {name: 'frank'});

The output here is: 'C:\\User{{name}}.txt' but I would have expected: 'C:\\User\\frank.txt'

Can that be fixed with some configuration? Is it expected behavior or simply a bug?

janober avatar Jan 28 '20 01:01 janober

Thank you @janober the backslash is used to escape the expressions that's why the \\{{name}} is not properly interpolated. I don't know if there is any way to solve this issue in a clean way maybe @aMarCruz could give us an hint. However this library is no longer maintained since it was used only in Riot.js 2 and 3. I would recommend to use the template literal for your use case, for example:

const renderPath = ({ name }) => `C:\\User\\${name}.txt`

renderPath({ name: 'frank' })

GianlucaGuarini avatar Jan 28 '20 07:01 GianlucaGuarini

@janober , please try with C:\\User\\\\{{name}}.txt

aMarCruz avatar Feb 05 '20 20:02 aMarCruz