2013-05-13 134 views
0

我所做的是使用Thymeleaf属性,但我不想要例如一个额外的div。没有html元素的Thymeleaf属性

例如,我有这样的

<div sec:authorize="hasRole('ROLE_ADMIN')"> 
    This content is only shown to administrators. 
</div> 

,但我想是这样的:

<sec:authorize="hasRole('ROLE_ADMIN')"> 
    This content is only shown to administrators. 
</> 

这可能吗?

+1

你发布的内容是无效的xml/html。 Thymeleaf希望有效的html(标签)具有可用于呈现视图的自定义属性。 – 2013-05-13 15:36:22

+0

嗨Sotirios,我知道这是无效的,是我需要的一个例子。你知道如何处理这个? – Federico 2013-05-13 15:43:17

+0

我想说的是,因为HTML没有这样的标记和Thymeleaf使用HTML标记来呈现模板,您将无法达到你想要什么Thymeleaf。据我所知,并不是。 – 2013-05-13 15:48:18

回答

3

您可以使用th:block标签:

<th:block sec:authorize="hasRole('ROLE_ADMIN')"> 
    This content is only shown to administrators. 
</th:block> 

从Thymeleaf文档:

日:块仅仅是一个属性的容器,它允许开发人员模板指定哪个属性他们想要的。 Thymeleaf将执行这些属性,然后简单地使块消失无踪。