# Library(http/html\_write): a conventional way to access title value

**URL:** <https://swi-prolog.discourse.group/t/library-http-html-write-a-conventional-way-to-access-title-value/1956>\
**Category:** Predicate\
**Tags:** http, web-prolog\
**Created:** [March 4, 2020, 1:13pm UTC](https://swi-prolog.discourse.group/t/library-http-html-write-a-conventional-way-to-access-title-value/1956 "2020-03-04T13:13:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![johndoe](https://avatars.discourse-cdn.com/v4/letter/j/65b543/32.png) [@johndoe](https://swi-prolog.discourse.group/u/johndoe)\
**Post date:** [March 4, 2020, 1:13pm UTC](https://swi-prolog.discourse.group/t/library-http-html-write-a-conventional-way-to-access-title-value/1956/1 "2020-03-04T13:13:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [March 4, 2020, 2:38pm UTC](https://swi-prolog.discourse.group/t/library-http-html-write-a-conventional-way-to-access-title-value/1956/2 "2020-03-04T14:38:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![johndoe](https://avatars.discourse-cdn.com/v4/letter/j/65b543/32.png) [@johndoe](https://swi-prolog.discourse.group/u/johndoe)\
**Post date:** [March 4, 2020, 3:21pm UTC](https://swi-prolog.discourse.group/t/library-http-html-write-a-conventional-way-to-access-title-value/1956/3 "2020-03-04T15:21:02Z")

</div>

That’s it, thanks.
