Dynamic Placeholder Replacement in Page Content via URL Parameters​ #5264

Closed
opened 2026-02-05 09:52:24 +03:00 by OVERLORD · 2 comments
Owner

Originally created by @Pjirlip on GitHub (Apr 17, 2025).

Describe the feature you'd like

I propose introducing a feature in BookStack that allows dynamic replacement of placeholder variables within page content using URL parameters.

This concept is inspired by the Mailcow documentation, where placeholders like ${MAILCOW_HOSTNAME} are automatically replaced with values provided through the URL.

Simple example:

In BookStack, this could be implemented by using placeholders such as {{VAR_NAME}} within the page content. When a page is accessed with corresponding URL parameters (e.g., ?VAR_NAME=example.com), these placeholders would be replaced with the specified values.

Describe the benefits this would bring to existing BookStack users

This feature would enable the creation of generic documentation templates that dynamically adapt to specific use cases. Users could view personalized content without the need to create multiple nearly identical pages.​

For instance, guides or configuration instructions could include variable placeholders that display specific information based on the provided parameters. This approach enhances the flexibility and reusability of documentation content and significantly reduces maintenance efforts.​

This feature aligns with previous discussions in the BookStack community, such as the request for global variables that load in-line with documentation text

Can the goal of this request already be achieved via other means?

As far as I know, it is not possible.

Currently, BookStack does not support dynamic placeholder replacement in page content via URL parameters.

While it's possible to manually create separate pages for different use cases or utilize custom scripting outside of BookStack to generate content dynamically, these approaches are not efficient or scalable. Implementing native support for dynamic placeholders would provide a more streamlined and maintainable solution within the BookStack platform.

Have you searched for an existing open/closed issue?

  • I have searched for existing issues and none cover my fundamental request

How long have you been using BookStack?

Under 3 months

Additional context

No response

Originally created by @Pjirlip on GitHub (Apr 17, 2025). ### Describe the feature you'd like I propose introducing a feature in BookStack that allows dynamic replacement of placeholder variables within page content using URL parameters. This concept is inspired by the Mailcow documentation, where placeholders like ${MAILCOW_HOSTNAME} are automatically replaced with values provided through the URL. Simple example: - (Without paramters) https://docs.mailcow.email/client/client-manual - (With paramters) https://docs.mailcow.email/client/client-manual#host=example.com&email=some.iuser%40example.com&name=some+user&ui=example.com&port=898 In BookStack, this could be implemented by using placeholders such as {{VAR_NAME}} within the page content. When a page is accessed with corresponding URL parameters (e.g., ?VAR_NAME=example.com), these placeholders would be replaced with the specified values. ### Describe the benefits this would bring to existing BookStack users This feature would enable the creation of generic documentation templates that dynamically adapt to specific use cases. Users could view personalized content without the need to create multiple nearly identical pages.​ For instance, guides or configuration instructions could include variable placeholders that display specific information based on the provided parameters. This approach enhances the flexibility and reusability of documentation content and significantly reduces maintenance efforts.​ This feature aligns with previous discussions in the BookStack community, such as the [request for global variables that load in-line with documentation text](https://github.com/BookStackApp/BookStack/issues/821?utm_source=chatgpt.com) ### Can the goal of this request already be achieved via other means? As far as I know, it is not possible. Currently, BookStack does not support dynamic placeholder replacement in page content via URL parameters. While it's possible to manually create separate pages for different use cases or utilize custom scripting outside of BookStack to generate content dynamically, these approaches are not efficient or scalable. Implementing native support for dynamic placeholders would provide a more streamlined and maintainable solution within the BookStack platform. ### Have you searched for an existing open/closed issue? - [x] I have searched for existing issues and none cover my fundamental request ### How long have you been using BookStack? Under 3 months ### Additional context _No response_
OVERLORD added the 🔨 Feature Request label 2026-02-05 09:52:24 +03:00
Author
Owner

@ssddanbrown commented on GitHub (Apr 17, 2025):

Hi @Pjirlip,

Can the goal of this request already be achieved via other means?
As far as I know, it is not possible.

This could potentially be achieved via methods of customization. Either some custom JavaScript added via the “Custom HTML Head Content” customization setting to make replacements on page load, or via the visual theme system to override the page display view and make replacements via PHP, or via the logical theme system to handle some form of custom include tags to perform the desired replacements.

Otherwise, due to limited past request and multiple workaround options, I probably wouldn't see it worth being something to be added to the core project.

If you'd like, I could maybe produce a basic JavaScript hack example? If so, what would you like to happen if the variable is not provided as a URL parameter? The variable blanked? Or left as-is?

@ssddanbrown commented on GitHub (Apr 17, 2025): Hi @Pjirlip, > Can the goal of this request already be achieved via other means? > As far as I know, it is not possible. This could potentially be achieved via [methods of customization](https://www.bookstackapp.com/docs/admin/hacking-bookstack/). Either some custom JavaScript added via the “Custom HTML Head Content” customization setting to make replacements on page load, or via the visual theme system to override the page display view and make replacements via PHP, or via the logical theme system to handle some form of custom include tags to perform the desired replacements. Otherwise, due to limited past request and multiple workaround options, I probably wouldn't see it worth being something to be added to the core project. If you'd like, I could maybe produce a basic JavaScript hack example? If so, what would you like to happen if the variable is not provided as a URL parameter? The variable blanked? Or left as-is?
Author
Owner

@Pjirlip commented on GitHub (Apr 17, 2025):

Hi @ssddanbrown ,

Thanks a lot for your super quick response!
You're absolutely right—I hadn't considered the possibility of adding custom JavaScript via the "Custom HTML Head Content". Given this option, the feature request is indeed obsolete, as the intended functionality can easily be implemented on the frontend with a bit of JavaScript.

To answer your question: yes, if no parameter is provided, the default value should be used.

In the meantime, I've already put together a function to handle this.
In case someone else stumbles upon this ticket and needs the same functionality, here's a code snippet they can place in the head:

<script>
  document.addEventListener("DOMContentLoaded", () => { 
        const content = document.querySelector("#main-content");
        const expr  = /{{([a-zA-Z0-9.;$\s]+):([a-zA-Z0-9.;$\s]+)}}/g;
        const params = new URLSearchParams(document.location.search);

        if(content?.innerHTML !== "") {
            content.innerHTML = content.innerHTML.replace(expr, (_, p, v) => {
                const paramter      = p.trim()
                const value         = v.trim()
                const valueOverride = params.get(paramter)

                return valueOverride ? valueOverride : value
            })
        }
  });
</script>

This will replace any text formatted like "{{ parameter : default }}" with either the provided parameter value from the URL or the default value.

I close the ticket accordingly.

Thanks again and best regards!

@Pjirlip commented on GitHub (Apr 17, 2025): Hi @ssddanbrown , Thanks a lot for your super quick response! You're absolutely right—I hadn't considered the possibility of adding custom JavaScript via the "Custom HTML Head Content". Given this option, the feature request is indeed obsolete, as the intended functionality can easily be implemented on the frontend with a bit of JavaScript. To answer your question: yes, if no parameter is provided, the default value should be used. In the meantime, I've already put together a function to handle this. In case someone else stumbles upon this ticket and needs the same functionality, here's a code snippet they can place in the head: ```html <script> document.addEventListener("DOMContentLoaded", () => { const content = document.querySelector("#main-content"); const expr = /{{([a-zA-Z0-9.;$\s]+):([a-zA-Z0-9.;$\s]+)}}/g; const params = new URLSearchParams(document.location.search); if(content?.innerHTML !== "") { content.innerHTML = content.innerHTML.replace(expr, (_, p, v) => { const paramter = p.trim() const value = v.trim() const valueOverride = params.get(paramter) return valueOverride ? valueOverride : value }) } }); </script> ``` This will replace any text formatted like "{{ parameter : default }}" with either the provided parameter value from the URL or the default value. I close the ticket accordingly. Thanks again and best regards!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#5264