您好,
我想知道是否可以从 ERB 文件访问主题设置?
我的用例如下:
我想检索在 Discourse Easy Footer (GitHub - discourse/Discourse-easy-footer) 中设置的页脚链接,并将其添加到页脚的 ERB 文件中,以便爬虫也能看到页脚链接。
感谢您的帮助。
您好,
我想知道是否可以从 ERB 文件访问主题设置?
我的用例如下:
我想检索在 Discourse Easy Footer (GitHub - discourse/Discourse-easy-footer) 中设置的页脚链接,并将其添加到页脚的 ERB 文件中,以便爬虫也能看到页脚链接。
感谢您的帮助。
技术上是的……如果主题的 id=5,你可以这样做:
<%= Theme.find(5).cached_settings["my_setting_name"] %>
但我强烈建议不要让核心或插件依赖于特定主题。如果主题被修改或卸载,可能会导致服务器错误,从而完全破坏你的网站。
你针对的是哪个爬虫?Google 吗?如果是,Google 在抓取时确实会运行 Javascript,并且主题的 Javascript 会包含在爬虫视图中。关键是你需要使用简单的 <script> 标签而不是 <script type="text/discourse-plugin">。
所以类似这样的东西应该可以在爬虫视图中工作:
<script>
document.body.append(`<a href="${settings.my_link}">footer link</a>`)
</script>