简体   繁体   English

Hybris:如何将类作为参数传递给 cms:component?

[英]Hybris: How to pass class as a parameter to cms:component?

I've started to learn Hybris and I want to find out how to pass the class as a parameter to a custom CMS Component (for the component's root element).我已经开始学习 Hybris,我想了解如何将类作为参数传递给自定义 CMS 组件(用于组件的根元素)。

Let's suppose that in a jsp file named customNavigationComponent.jsp I have this piece of code:假设在一个名为customNavigationComponent.jsp的 jsp 文件中,我有这段代码:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="cms" uri="http://hybris.com/tld/cmstags"%>

<c:forEach items="${navigation.entries}" var="navigationLink">
    <div class="custom-component-wrapper">
        <cms:component component="${navigationLink.item}"/>
    </div>
</c:forEach>

And the custom component looks like this:自定义组件如下所示:

<a href="${component.url}">
    <div>${component.linkText}</div>
</a>

I would like to understand what I need to do to pass the class navigation-link as a parameter, like this:我想了解我需要做什么才能将类navigation-link作为参数传递,如下所示:

<cms:component component="${navigationLink.item}" class="navigation-link"/>

so that the rendered result will be similar to:这样渲染的结果将类似于:

<a href="stackoverflow.com" class="navigation-link">
    <div>Lorem Ipsum</div>
</a>

There is no attribute called, class in cms:component and therefore the following statement will not work: cms:component没有名为class属性,因此以下语句将不起作用:

<cms:component component="${navigationLink.item}" class="navigation-link"/>

Please check https://help.sap.com/doc/a4265d5ea8314eb2929e6cf6fb8e35a5/1811/en-US/de/hybris/platform/cms2lib/cmstags/CMSComponentTag.html请检查https://help.sap.com/doc/a4265d5ea8314eb2929e6cf6fb8e35a5/1811/en-US/de/hybris/platform/cms2lib/cmstags/CMSComponentTag.html

In order to understand it better, you can compare it with c:forEach .为了更好地理解它,您可以将其与c:forEach进行比较。 At https://docs.oracle.com/javaee/5/jstl/1.1/docs/tlddocs/c/forEach.html , you will find a list of attributes available with c:forEach and if you want to dig deeper, you can further check https://tomcat.apache.org/taglibs/standard/apidocs/javax/servlet/jsp/jstl/core/LoopTagSupport.htmlhttps://docs.oracle.com/javaee/5/jstl/1.1/docs/tlddocs/c/forEach.html ,您将找到c:forEach可用的属性列表,如果您想深入挖掘,您可以可以进一步检查https://tomcat.apache.org/taglibs/standard/apidocs/javax/servlet/jsp/jstl/core/LoopTagSupport.html

If you want to use your statement, you will need to create a custom tag.如果要使用语句,则需要创建自定义标记。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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