我们公司有多个品牌,每个品牌都有自己的主机名,但它们都是同一网站的一部分。我们可以让客户在使用 URLUtils.sessionRedirect
通过重定向链接在品牌之间切换时共享购物篮和其他 session 信息。
但是 URLUtils
在内容 Assets 中不可用。是否可以在保留所有 session 信息的内容 Assets 中形成 session 重定向链接?
提前致谢。
最佳答案
您可以使用 $include('Controller-Name', 'name1', 'value1', 'name2', 'value2', ...)$ 在内容 Assets 中包含动态内容
句法。请参阅MarkupText Class Documentation有关该语法的更多信息。 'name1' 和 'value1' 参数映射为查询字符串属性,例如:Controller-Name?name1=value1&name2=value2
创建一个输出所需 session 重定向链接的 Controller ,并通过以下语法调用它:$include(Util-RenderSessionLink, 'siteID', 'foo')$
Controller 需要使用 text/plain
或类似内容的响应 Content-Type header ,以便不会将任何内容注入(inject)到响应中。 (例如:店面工具包或跟踪标签)例如:
response.setContentType('text/plain');
或者,您可以处理内容 Assets 以获取对其执行查找和替换操作的某些类型的键。例如,以下代码对内容 Assets 的正文内容执行查找和替换键:“%%SessionLink%%”。
var ContentMgr = require('dw/content/ContentMgr');
var URLUtils = require('dw/web/URLUtils');
if (!empty(content) {
var content = ContentMgr.getContent('my-content-id');
var contentOut = "";
var viewData = {};
contentOut = content.custom.body.getMarkup()
.replace('%%SessionLink%%', URLUtils.sessionRedirect(...));
viewData.content = contentOut;
// then output your `pdict.content` key within a template with the appropriate encoding
}
关于demandware - 在内容 Assets 中创建 session 重定向链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65512377/