6 Explain the MVC pattern in SFRA and the role of pdict.
Suggested answer
SFRA implements the Model-View-Controller pattern across three cartridge sub-directories:
1. Model (cartridge/models/) — JavaScript modules that encapsulate business logic and transform raw commerce objects (products, baskets, orders) into clean view models. They interact with B2C Commerce scripting APIs and expose simple properties to the controller.
2. Controller (cartridge/controllers/) — JavaScript files that register HTTP routes, call model methods to get view model data, and pass that data to a template via res.render().
3. View (cartridge/templates/) — ISML files that generate HTML using data from pdict.
The pdict (Pipeline Dictionary) is the data object that flows from controller to template. When a controller calls res.render('path/template.isml', { product: productModel }), the second argument is merged into pdict. In the ISML template, you access it as ${pdict.product.name} or via <isprint value="${pdict.product.price}">.
Practice content for interview preparation; not an official vendor answer. Verify details against current product documentation.
Community comments (0)
No comments yet.
Sign in or create a free account to add a comment. Comments are moderated before they appear.