]> BookStack Code Mirror - hacks/blob - content/page-include-tag-value/index.md
Added page-include-tag-value hack
[hacks] / content / page-include-tag-value / index.md
1 +++
2 title = "Tag Values in Page Content via Includes"
3 author = "@ssddanbrown"
4 date = 2025-08-16T00:00:00Z
5 updated = 2025-08-16T00:00:00Z
6 tested = "v25.07.1"
7 +++
8
9 This hack allows you to dynamically pull in the value of tags into page content, via customizing how [page include tags](/docs/user/reusing-page-content/#include-tags) are parsed. 
10 This hack will attempt to use tags on the page itself, then look to the parent chapter (if existing), then the parent book's tags.
11
12 #### Usage
13
14 Within page content, insert [an include tag](/docs/user/reusing-page-content/#include-tags) with the following specific format:
15
16 ```text
17 {{@0tag:<tag-name>}}
18 ```
19
20 Replacing `<tag-name>` with the name of your intended tag. The tag lookup is performed case-insensitive, so don't worry about correct casing. The hack will then replace the include tag with the value of any relevant tags found, or otherwise blank out the include tag.
21
22 As an example, if I had a tag with name `Color` and value `Blue`, I'd use the include tag `{{@0tag:color}}` which will be replaced with `Blue` (using the tag value) when the page is shown.
23
24 #### Considerations
25
26 - This is subject to many of the same limitations as page includes, so the values won't show in things like preview snippets.
27 - This implementation does not consider permissions/access to parent chapter/book for tag values, so values may be used from chapters/books which the user does not have access to view.
28 - Tag name matching is case-insensitive.
29
30
31 #### Code
32
33 {{<hack file="functions.php" type="logical">}}