JSONstringify and double curly braces
ileana2019 opened this issue · 2 comments
Hello,
I am using the PnP modern search in SharePoint which is using the handelbars-helpers. One of the web components inside is the pnp-details-list with the following properties (which works fine, using the JSONstringify inside the data-columns-configuration):
<pnp-details-list data-items="{{JSONstringify items}}" data-columns-configuration="{{JSONstringify detailsListColumns}}" data-show-file-icon="{{@root.showFileIcon}}" data-is-compact="{{@root.isCompact}}"></pnp-details-list>
If I replace the data-columns-configuration with the following:
data-columns-configuration="[{"uniqueId":"986cc099-2e5f-47e9-8b3e-aaa4bcaf8f50","name":"Actions","value":"{%replace ParentLink 'AllItems' 'DispForm'%}","useHandlebarsExpr":true,"minWidth":"70","maxWidth":310,"enableSorting":null,"isResizable":null,"isMultiline":null,"isResultItemLink":null,"sortIdx":1}]"
it doesn't work anymore (the value inside the JSON is ""; I expect it to be "{{replace ParentLink 'AllItems' 'DispForm'}}" in the DOM).
data-columns-configuration corresponds to this JSON:
[{ "uniqueId": "986cc099-2e5f-47e9-8b3e-aaa4bcaf8f50", "name": "Actions", "value": "{{replace ParentLink 'AllItems' 'DispForm'}}", "useHandlebarsExpr": true, "minWidth": "70", "maxWidth": 310, "enableSorting": null, "isResizable": null, "isMultiline": null, "isResultItemLink": null, "sortIdx": 1 }]
I think it is because of the double curly braces which are interpreted as a code and not as string inside the template.
So how can I use JSONstringify to stringify the above JSON?
I also created an issue on the pnp-modern-search github and they advise to contact this forum.
Thanks!
I think I have the same problem with you. I was trying to hardcode the list column config into the details list layout.
This worked for me:
- html escape the json value
- put an "\" (backslash) in front of any opening double curly bracket
So, your template was:
<pnp-details-list data-items="{{JSONstringify items}}" data-columns-configuration="{{JSONstringify detailsListColumns}}" data-show-file-icon="{{@root.showFileIcon}}" data-is-compact="{{@root.isCompact}}"></pnp-details-list>
with the {{JSONstringify detailsListColumns}} equal to:
[{ "uniqueId": "986cc099-2e5f-47e9-8b3e-aaa4bcaf8f50", "name": "Actions", "value": "{{replace ParentLink 'AllItems' 'DispForm'}}", "useHandlebarsExpr": true, "minWidth": "70", "maxWidth": 310, "enableSorting": null, "isResizable": null, "isMultiline": null, "isResultItemLink": null, "sortIdx": 1 }]
--> this should work:
<pnp-details-list data-items="{{JSONstringify items}}" data-columns-configuration="[{ "uniqueId": "986cc099-2e5f-47e9-8b3e-aaa4bcaf8f50", "name": "Actions", "value": "\{{replace ParentLink 'AllItems' 'DispForm'}}", "useHandlebarsExpr": true, "minWidth": "70", "maxWidth": 310, "enableSorting": null, "isResizable": null, "isMultiline": null, "isResultItemLink": null, "sortIdx": 1 }]" data-show-file-icon="{{@root.showFileIcon}}" data-is-compact="{{@root.isCompact}}"></pnp-details-list>