In Vapor, specifically in the class for a custom Leaf tag, how can you retrieve values stored in a context?
I'm trying to implement a tag that takes a string and a path, and renders a link unless the path is the current page, so, for example, #navElement("About Us", "/about")
will produce a link to the site's about page on every page except the about page itself. On that page, it should display the text without a link on it.
I don't want to have to pass the current path to the tag every time I use it, so I've stored the request's path in the context, roughly like this (checks omitted):
drop.get(":page"){ request in
return try drop.view.make(thePage, ["path": request.uri.path])
}
I can use #(path)
in a template and see the path I expect.
My custom tag is derived from Tag
, and its run
method receives the context as an argument, and I can see the stored value in there in the debugger – but how do I get at it? The get
method in the Context
class, which seems to do this, is internal
, so I can't use it. There is a comment that says subscripts are to be done, and I assume that this will ultimately be the way to extract values from the context, but in the meantime, is there any way to retrieve them?