简体   繁体   中英

BigCommerce Stencil Custom Fields

I currently have a use-case for a BigCommerce Stencil site where I have to display custom field values in various places on the Item Page. I know that I can use Handlebars to loop through the custom fields finding the specific one that I want, and then display it on the page. Does anyone have insight on how this will affect page speed? None of these loops will be nested or anything, there will just be multiple loops on the page.

We do this all the time, and several loops will not noticeably affect page speed. But if you do feel it's causing an issue, you can just loop through the custom_fields once, drop them in a json array, and use javascript loops to populate the data where necessary. We do this as well, because the supplied handlebars functions for conditionals and string replacement are so limited and it becomes much easier to handle it all with standard javascript.

<script>
var custom = [];
{{#each product.custom_fields}}
custom.push({'name':"{{name}}",'value':"{{value}}"});
{{/each}}
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM