-
-
Notifications
You must be signed in to change notification settings - Fork 38
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
Custom tags with body #86
Comments
+1, this feels like it should be straightforward as A slightly more complex case that I was hoping to solve with a custom tag is injecting common variables without needing to set them in the view model. For example...
When building re-usable templates such as navigation, there are many use-cases for wanting common data available without needing to add all that common context to the view model/controller. I guess this could all be bundled up into some common view model type, but that's still extra code that's required. |
How to return let body = try ctx.requireBody()
guard case let .raw(byteBuffer) = body.first else {
throw "Body not found"
}
return .data(Data(buffer: byteBuffer)) Make sure your custom tag conforms to |
I tried to define a custom tag that accepts a body, but the body is provided to the tag as
[Syntax]
, which is not something that converts to the required return type ofLeafData
.How can I capture the body, and return if necessary?
For context, I'm trying to create
requireRole(role)
tag, that returns the body if the role matches the role of the current user;In the tag class I retrieve the body using
ctx.requireBody()
, which, as mentioned, returns an array ofSyntax
elements.The text was updated successfully, but these errors were encountered: