Project

General

Profile

Actions

Improvements #10303

open

WTemplate: support extra args as attributes

Added by Emeric Poupon almost 2 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Target version:
-
Start date:
05/06/2022
Due date:
% Done:

0%

Estimated time:

Description

Today we have this:

void WTemplate::applyArguments(WWidget *w, const std::vector<WString>& args)
{
  for (unsigned i = 0; i < args.size(); ++i) {
    std::string s = args[i].toUTF8();
    if (boost::starts_with(s, "class="))
      w->addStyleClass(WString::fromUTF8(s.substr(6)));
  }
}

It is quite easy to make other args set html attributes using WWidget::setAttributeValue

I have to override Wt::WTemplate to override applyArguments to do this, and it would be quite handy that Wt handles this.
What do you think?

Use case example on a bootstrap5 template:

<div class="dropdown">
    ${more-btn class="btn btn-outline-primary" data-bs-toggle="dropdown" aria-expanded="false"}
    <ul class="dropdown-menu" aria-labelledby="${id:more-btn}">
        <li>${play-shuffled class="btn dropdown-item"}</li>
        ...
    </ul>
</div>

No data to display

Actions

Also available in: Atom PDF