You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The problem is that the blockregex will match the first {{@_val}} with the very first {{/@_val}} it finds, not the second one, which is the correct one.
I've found a relatively easy solution to this by a minor tweek to the regular expression. Here you have both the original and my suggested one:
var blockregex = /\{\{(([@!]?) (.+?) )\}\}(([\s\S]+?)(\{\{:\1\}\}([\s\S]+?))?)\{\{\/\1\}\}/g,
var blockregex = /\{\{(([@!]?)([\.\w]+)[\s\S]*?)\}\}(([\s\S]+?)(\{\{:\1\}\}([\s\S]+?))?)\{\{\/\1\}\}/g;
I left a couple of gaps in the original one to highlight the change, just a few characters.
What it does is to allow an optional label in the placeholder to clearly specify the matching tags, like this:
The labels (year, month) are optional and can be omitted (like in {{@qtys}} which is not ambiguous).
The label can be separated from the tag by anything other but a valid variable name, that is, it doesn't need to be a space, you could write {{@_val-month}} and it would do just fine. As a matter of fact, the space (or any separator) is part of the label. The exact label, including the separator spaces or whatever was used must be replicated verbatim on the closing tag, thus, a single space before and none after the label is preferred for clarity and consistency. I omitted checking for spaces so to add as fewest bytes to the already small size of the library.
Well chosen labels can help document what _val actually stands for.
This issue is actually a suggestion and requires no reply. Feel free to close. (and thanks for this little, really little, gem)
The text was updated successfully, but these errors were encountered:
Satyam
added a commit
to Satyam/t.js
that referenced
this issue
Oct 16, 2023
Sometimes you have nested loops suitable for a tree-view kind of display. For example:
And you want to display it like this:
The problem is that the
blockregex
will match the first{{@_val}}
with the very first{{/@_val}}
it finds, not the second one, which is the correct one.I've found a relatively easy solution to this by a minor tweek to the regular expression. Here you have both the original and my suggested one:
I left a couple of gaps in the original one to highlight the change, just a few characters.
What it does is to allow an optional label in the placeholder to clearly specify the matching tags, like this:
The labels (
year
,month
) are optional and can be omitted (like in{{@qtys}}
which is not ambiguous).The label can be separated from the tag by anything other but a valid variable name, that is, it doesn't need to be a space, you could write
{{@_val-month}}
and it would do just fine. As a matter of fact, the space (or any separator) is part of the label. The exact label, including the separator spaces or whatever was used must be replicated verbatim on the closing tag, thus, a single space before and none after the label is preferred for clarity and consistency. I omitted checking for spaces so to add as fewest bytes to the already small size of the library.Well chosen labels can help document what
_val
actually stands for.This issue is actually a suggestion and requires no reply. Feel free to close. (and thanks for this little, really little, gem)
The text was updated successfully, but these errors were encountered: