-
-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to create a custom tag/element? #80
Comments
No, we do not have support for custom Elements yet. It is a nice feature and I would like to include it in HtmlFlow DSL. We will have to discuss the best way to do it. But I think that we should place some effort to develop it soon. We will analyze it an then I will give a estimated date here soon. It would be useful if you could provide your use cases on custom elements use. Regarding HTML fragments/partials support and reuse, we can already do it in HtmlFlow in an unopinionated manner. There is some lack of details in documentation but there is a high level idea here about that: https://htmlflow.org/features/#partial-and-layout. |
@iyerha we may have 2 options:
Is this a realistic use of custom elements and an example of the desired output? |
That is the typical usage. Solution 1 looks good enough. On a separate note, we also use custom data attributes in regular html. |
@iyerha What kind of content can we find inside a custom element? Always empty? Text? Text or other custom element? Or text or any kind of other elements? Is this a valid example? <my-custom-element>
<ul>
<li>...</li>
...
</ul>
</my-custom-element> |
All of the above. That is a valid example. |
@lcduarte With the new custom element feature we should be able to define HtmlFlow views such as the listing at the end of this comment (this feature applies regardless being a static or a dynamic view). I think that invoking Moreover, that class @Override
public final void visitElement(Element element) {
newlineAndIndent();
if (isWriting()){
beginTag(element.getName()); // "<elementName"
isClosed = false;
}
} So, the HtmlView viewWithCustomElements() {
return StaticHtml
.view()
.html()
.head()
.script()
.attrSrc("alert.js") // Link to alert-info definition
.attrDefer(true)
.__()
.__()
.body()
.div()
.attrClass("container")
.p().text("Testing custom elements!").__()
.custom("alert-info") // alert-info should be stored in the new Element and accessible to the Visitor.
.addAttr("title", "Information")
.addAttr("message", "This is a message for a custom element")
.addAttr("kind", "success")
.ul()
.li().text("For any reason we could even include other elements.").__()
.__() // ul
.__() // alert-info
.__() // div
.__() // body
.__(); //html
} |
Hello, This change looks doable, I'll investigate it further on the weekend and I'll prepare the changes needed. |
Hi, I've made the required changes on our related projects and I've added a new test in the development branch to validate the example provided above. |
@iyerha Just released HtmlFlow 3.9 with support for custom elements as announced here: https://htmlflow.org/2022/01/30/Release-3.9/ I will wait a few days and if there is no more updates on this issue I will close it. |
I am evaluating htmlFlow for our project. We are using web components and don't see how custom elements are supported. I see that kotlinx.html has support for the same and I am hoping that htmlFlow has an equivalent feature.
The text was updated successfully, but these errors were encountered: