-
Dear nicegui developers, I was wondering if it is possible to modify a page title while generating the page, specifically based on input from the path, something like: @ui.page('/detail/{item_id}', title="static title")
async def page_application_display_detail(item_id: str):
# do something
page_title = "new dynamic title" + item_id The idea would be to have the page respond to user input such as "Your search for item XZY" instead of having to set a fixed title. Maybe this is already possible, but I could not find any related code/discussion/issues. Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
Sure. You can run javascript as soon as the client has connected: from nicegui import ui, Client
@ui.page('/')
@ui.page('/{path:path}')
async def index(path: str, client: Client):
await client.connected()
await ui.run_javascript(f'document.title = "{path or "nothing"}";', respond=False)
ui.run() |
Beta Was this translation helpful? Give feedback.
-
Thank you very much, works beautifully! |
Beta Was this translation helpful? Give feedback.
-
Potentially helpful for users in the future regarding this topic: While the <title> is now shown correctly in the browser window, my main reason for having specific title tags is to improve visibility in search engines. I was wondering if this change (which happens on the client site) would be reflected in search hits generated by Google and Bing. As it turns out, search engines may execute the client side javascript to improve results, Google seems to be among them: https://stackoverflow.com/questions/30588501/seo-affected-changing-title-tag-by-javascript As such, this approach should work for the sake of SEO. I will report in some time, once my page has been picked up the the search engines. |
Beta Was this translation helpful? Give feedback.
Sure. You can run javascript as soon as the client has connected: