Rendering Pages Best Practices

Rendering Templates

When Salesforce Commerce Cloud generates web pages on the application server, it uses ISML Templates and scripts within the Controllers. B2C Commerce Script API in the Controllers access the database layer if necessary. We are going to describe the best practices for:

  • ISML Templates
  • Scripting in Templates
  • Local Includes
  • Remote Includes
  • Efficient Template Coding

ISML Templates

You should keep ISML as clean as possible. It’s always good for performance tuning and maintainability of your site.

Scripting in ISML Templates

You can write Salesforce Commerce Cloud scripts inside ISML templates using <isscript> tag. In general though, you should use scripts in your controllers and passing the information via viewData rather than using <isscript> blocks and be sure to keep them small. To ensure that you can diagnose performance issues, break large <isscript> blocks in the templates into multiple pieces. With smaller scripts, you’ll be able to pinpoint bottlenecks more efficiently. Smaller scripts also help with readability.

Local Includes

Local includes are useful when you want to reuse partial templates. They are simply merged with the including template as an ISML file before it is compiled.

Pipeline dictionary variables (pdict) can be used in the included templates as well. You don’t haveto initialize and fetch data if the variables are already available in the  pipeline.

<isinclude template=”/components/your-template.isml” />

Remote Includes

For each remote include in a page, a placeholder is inserted and a page is delivered from the application server to the web server. The web server parses the page and calls for every include placeholder the application server again (as long as this is not cached already). This could cause “Ping-Pong” between the two servers. Use care with remote includes:

  • Do not use more than 20 remote include positions within a page, any <isslot> (content slot placeholder) will cause one remote include for the configuration and one remote include for the content.
  • Do not exceed three levels of remote includes.
  • As you lose the pipeline dictionary between the main page and the included page, everything that is difficult to determine (like a search result, couple of custom object queries, etc.) should be reused within the pipeline and not split into multiple pieces.

<isinclude url=”${URLUtils.https(‘Home-Show’)}” />

Best Practices for Efficient Template Coding

  • Controllers should capture most of the business logic. Templates are supposed to only render information that was aggregated in the Controllers.
  • Use pagination to display large search result set.
  • Remove unused SFRA/SiteGenesis ISML templates and code, or hide from public view to prevent unnecessary resource consumption.
  • When you need to decorate the enclosed content with the contents of the specified (decorator) template, use <isdecorate> tag. A decorator is an ISML template that has HTML, CSS and the overall page design. A typical use case is to decorate the content body with a header and footer.
  • Use ismodule when you have code snippets reused in multiple templates.

How to be a Certified Salesforce Commerce Cloud Developer for FREE

Unlock a FREE PDF with SFCC B2C Certification questions from our Udemy Course. Join our newsletter!
Check your email, you’ll receive a copy in a few seconds. If you don’t see it, please check your spam folder.

Do you like cookies? 🍪 We use cookies to ensure you get the best experience on our website. Learn more.