#Set footer in template file using main file

4 messages · Page 1 of 1 (latest)

drowsy mist
#

I made a template that has a footer I'd like to expose so I can set it in the main file. I have this code, but when I try to compile it, typst says "variables from outside the function are read-only and cannot be modified"

is there a way to do this?

// === template file
#let footer_text = ""

#let set_footer(txt) = {
  footer_text = txt
} 
  
#let template(doc) = [
  #set page(
    paper: "us-letter",
    footer: [#set text(10pt);#h(1fr)#footer_text],
  )
  #doc
]

// === main file
#import "tools/formatting.typ": *
  
#set_footer("Math | 461 | Quiz 1 | 30/9/2024")
#show: template
digital night
#

Use states or pass it to the set rule through an argument

drowsy mist
# digital night Use states or pass it to the set rule through an argument

thanks for letting me know about states, never heard of them. I got it working. this is the code for reference:

// === template file
#let s = state("footer_text", "-1")

#let set_footer(expr) = [
  #s.update(footer_text => expr)
]

#let template(doc) = [
  #set page(
    paper: "us-letter",
    footer: [#set text(10pt);#h(1fr)#context s.get()],
  )
  #doc
]

// === main file
#import "tools/formatting.typ": *
#show: template
#set_footer("Math | 461 | Quiz 1 | 24/2/2024")
digital night