How do I add links to site settings into the settings description of my component?

AI-generated summary

Moin is having trouble adding working links to site settings within the description of a Discourse component. Initially, simple <a href> tags worked, but tests now require %{base_path} or %{base_url}, which resulted in broken links due to URL encoding issues (e.g., %{base_url} becoming %%7Bbase_url%7D). Moin tried multiple variations with and without trailing slashes, but none were successful. They referenced a broken link in the homepage feature component as well.

david informed Moin that a PR (https://github.com/discourse/discourse/pull/33180) enabling the use of %{base_path} in theme setting descriptions has been merged, and a corresponding PR to fix the homepage component (https://github.com/discourse/discourse-homepage-feature-component/pull/58) was created.

Moin then considered pinning the component version in compatibility to ensure continued functionality for users who haven’t updated their Discourse installation. david confirmed this reasoning, as the original relative links were already working and pinning the version would maintain that functionality.

Actually, I thought I knew because I translated something like <a href="/admin/site_settings/category/all_results?filter=top_menu">top menu site setting</a> several times, and it worked :tada:.
But the tests fail because links without %{base_path} or %{base_url} aren’t allowed.
image

So I searched for an example and found
https://github.com/discourse/discourse-homepage-feature-component/blob/0d4a895d8913a3f55e68667255be9ad3a869eb56/locales/en.yml#L7C61-L7C72

I copied that:

<a href="%{base_url}/admin/site_settings/category/all_results?filter=top_menu">top menu site setting</a>

But then the link didn’t work. It became https://example.discourse.group/%%7Bbase_url%7D/admin/site_settings/category/all_results?filter=top_menu

When I installed https://meta.discourse.org/t/homepage-feature-component/144264, the link there didn’t work either.

So I tried adding a trailing slash and using %{base_url}, but none of them worked.

<a href="/%{base_url}/admin/site_settings/category/all_results?filter=top_menu">top menu site setting</a> links to https://example.discourse.group/admin/customize/themes/%%7Bbase_url%7D/admin/site_settings/category/all_results?filter=top_menu

<a href="%{base_path}/admin/site_settings/category/all_results?filter=top_menu">top menu site setting</a> links to https://example.discourse.group/admin/customize/themes/%%7Bbase_path%7Dadmin/site_settings/category/all_results?filter=top_menu

<a href="/%{base_path}/admin/site_settings/category/all_results?filter=top_menu">top menu site setting</a> links to https://example.discourse.group/%%7Bbase_path%7D/admin/site_settings/category/all_results?filter=top_menu

But I wasn’t able to find a working solution

Once this PR is merged, you’ll be able to use %{base_path} in theme setting descriptions:

https://github.com/discourse/discourse/pull/33180

The core change is merged, and I’ve made a PR to fix the “homepage feature” theme component:

https://github.com/discourse/discourse-homepage-feature-component/pull/58

Since the relative links in the description of the settings of my component are currently working, I assume I should pin the version in compatibility to ensure they continue to work for those who don’t update Discourse at the same time.
I guess you didn’t pin because the links didn’t work before anyway — is that correct?

Yup that’s correct :+1: