#How do you change the title of a page inside lustre?

1 messages · Page 1 of 1 (latest)

true bison
#

Hey all.

How can I change the <title> inside the <head> of a page, dynamically, in lustre?
#lustre

mystic forge
#

lustre only owns the part of the dom you mount it on so this isn't really lustre's concern

#

you'd write an ffi function to set window.title and then you'd call that function in an effect from your update function

true bison
frank plinth
#

good post, just noting that the function set_window_title there is redundant as all it does is call the other function

mystic forge
#

there's a little more to it if you want to do it the correct way for lustre

#

specifically, i would do this:

import lustre/effect.{type Effect}

pub fn set_window_title(title: String) -> Effect(msg) {
  use _ <- effect.from
  do_set_window_title(title)
}

@external(javascript, "./set_window_title.js", "set_windowTitle")
pub fn do_set_window_title(title: String) -> Nil

and then in your update function you would do

fn update(model, msg) {
  case msg {
    Whatever -> #(model, set_window_title("wibble"))
  }
}