Genie Discord forum

Author AvatarDaveMacMahon
2/26/2023, 2:48:51 AM

I'm writing a GenieBuilder app that uses @page("/", "app.jl.html"). I'd like to render different views depending on the contents of the User-Agent header, but I'm unclear how to do this using the @page macro. Is this possible or will I have to switch to calling route() directly? How would either solution look?

Author AvatarPere
2/26/2023, 3:37:01 PM

In order to access the route parameters you'd have to use the low-code Stipple API instead of defining the UI with HTML.

Define a ui() function, and in it you can access the route parameters with Genie.Router.params. Just make sure that the function returns the UI as an array of calls to the StippleUI API

using GenieFramework
@genietools

@handlers begin end

function ui()
    params = Genie.Router.params()
    println(params)
    [cell("Div 1"), cell("Div 2")]
end

@page("/", ui)
Author AvatarDaveMacMahon
2/26/2023, 8:17:27 PM

Thanks. Is there any way to utilize GB's app.jl.html file from within ui()?

Author AvatarPere
2/27/2023, 9:58:38 AM

Good question! I had not thought of that. Yes, you can also return a string with the HTML code. Just read the html file:

function ui()
    pload = Genie.Router.params()
    println(pload)
    read("app.jl.html", String)
end