Access theme settings from Ruby ERB

Hello,

Would like to know if it’s possible to access theme settings from a an ERB file?

My use case is following:

I would like to retrieve footer links set in Discourse Easy Footer (GitHub - discourse/Discourse-easy-footer) and add it in ERB file for footer in order for crawlers to see footer links as well.

Thanks for the help.

2 Likes

Technically yes… if the theme had id=5 you could do something like

<%= Theme.find(5).cached_settings["my_setting_name"] %>

But I would strongly recommend against making core, or a plugin, depend on a specific theme. If the theme is modified or uninstalled, it could cause server errors that would totally break your site.

What crawler are you targetting? Google? If so, Google does run Javascript when crawling, and theme javascript is included in the crawler view. The key thing is that you need to use a simple <script> tag rather than a <script type="text/discourse-plugin">.

So something along these lines should work in the crawler view:

<script>
  document.body.append(`<a href="${settings.my_link}">footer link</a>`)
</script>
3 Likes