Library(http/html_write): a conventional way to access title value

What I’m trying to achieve is prepending of a global site name to the titles provided by handler rules. That is, every page has title('Stuff') defined in their respective reply_html_page predicates and the end result I expect is ... <title>MySite: Stuff</title> ... on every page.

It seems user:head(Name, Head) --> ... could be a solution with Head matching to html_write:title(X), html_write:[title(X)], or html_write:[...,title(X),...]. But how do we approach the extraction of title from Head exactly, is there any standard mechanism in the toolbox? Ideally, I would like to avoid reinventing the wheel and cluttering my layouts with anything unrelated to layout.

One of the solutions is to use reply_html_page/3 and exploit the style argument, using a compound term where you pass the title (and whatever more). You get this style parameter as the first argument of user:head(Style, Head). This is more robust as you do not to rely on Head except that you can emit it using html//1.

Parameterized styles are used a lot in for example the SWI-Prolog website, where the page//3 rule adds headers and footers and provides style sheets and JavaScript resources depending on the page style.

That’s it, thanks.