Skip to main content

Hello,

I am doing an exercise where I need to pass data to the response (setViewdata) but when trying to do so, I get an error:

Error: Cannot render template without name or data in controller Basket

 

What am I doing wrong ?

Thanks for your help.

 

isml template:

<isloop items="${pdict.Basket.getProductLineItems()}" var="productLineItem" status="loopstate">

${productLineItem.productName}<br/>

Count ${loopstate.count} Index ${loopstate.index} ${productLineItem.product.name}<br/>

</isloop>

 

controller js:

"use strict";

var server = require("server");

var BasketMgr = require("dw/order/BasketMgr");

server.get("Show", function (req, res, next) {

// Pass viewData to the template

var basket = BasketMgr.getCurrentBasket();

res.setViewData({ Basket: basket });

next();

});

module.exports = server.exports();

#B2C Commerce #SFCC 

답변 1개
  1. 2022년 10월 25일 오전 8:55

    You have a endpoint without any rendering, so there is no link to the isml you are mentioning above. You need:

    res.render('/your/template', {

    Basket: basket

    });

    And the object you add into the rendering method is the viewData object for the response. So you can skip using "res.setViewData({ Basket: basket })" explicitly. This call typically becomes relevant if you use the append/prepend mechanisms or other situations where you want to add something from another place other than the rendering controller.

0/9000