Skip to content

Default attribute support #297

Closed
Closed

Description

@danielfernandez

It could be useful to add a "default attribute processor" that simply matches any name (with the lowest precedence, so that it acts as a default) and outputs an attribute with the same matched name, with value equal to the evaluated expression.

Something like:

<span th:whatever="${somevalue}">
<span data-th-whatever="${somevalue}">

with output:

<span whatever="02412">

Activity

  1. added this to the Thymeleaf 3.0 milestone on Jun 23, 2014
  2. ultraq commented on Jun 23, 2014

    @ultraq
    Member

    Could this be a replacement for all the HTML attribute processors we have? (th:class, th:href, th:selected...)

  3. danielfernandez commented on Jun 23, 2014

    @danielfernandez
    MemberAuthor

    Not all, but many of them. For example, th:selected works differently, because it evaluates its expression as boolean and outputs selected="selected" if true, and does not output at all if false.

    Also, some attributes are actually required, so when evaluating to a null expression they must not dissapear from the tag, but simply output the empty string, like <form action="">. These would not be replaced either.

  4. Antibrumm commented on Jun 24, 2014

    @Antibrumm

    What if you simply manage a list of attributes that allow null to empty string conversion?

    Also: Probably the same approach could be possible for append and prepend processors?

  5. danielfernandez commented on Sep 27, 2015

    @danielfernandez
    MemberAuthor

    Default attribute support has been implemented in Thymeleaf 3.0, for the Standard Dialects.

    Already in 3.0.0-SNAPSHOT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions