[英]Including External 3rd party scripts in Apostrophe CMS project
How do you push a 3rd party script from a custom module in Apostrophe CMS?如何从 Apostrophe CMS 中的自定义模块推送 3rd 方脚本?
I am followingthis helpful tutorial to build a form for my Apostrophe CMS site.我正在按照这个有用的教程为我的 Apostrophe CMS 站点构建一个表单。 I am needing to put a reCaptcha thing on the form ( https://developers.google.com/recaptcha/docs/display ) and I am not following how to include the needed script from google.
我需要在表单( https://developers.google.com/recaptcha/docs/display )上放一个 reCaptcha 东西,我没有遵循如何从谷歌包含所需的脚本。 Note that I need to pass in a variable via the script file include url, ie:
<script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit" async defer></script>
请注意,我需要通过脚本文件包含 url 传入一个变量,即:
<script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit" async defer></script>
Is there already a widget created (like Apostrophe-twitter ) that I could reference to understand how to include this extra script?是否已经创建了一个小部件(如Apostrophe-twitter ),我可以参考它来了解如何包含这个额外的脚本?
**Edit I can get the job done by creating a block in my root template, ie: {% block customAssets %} {% endblock %}
, then 'populating' the block with my necessary includes from my contact-form-widget:widget.html file. **编辑我可以通过在我的根模板中创建一个块来完成工作,即:
{% block customAssets %} {% endblock %}
,然后用我的联系表单小部件中的必要包含“填充”块:小部件.html 文件。 Is there a better way of doing this task?有没有更好的方法来完成这项任务?
I am the lead developer of Apostrophe at P'unk Avenue.我是 P'unk Avenue 的 Apostrophe 的首席开发人员。
For most cases, you can call pushAsset
, just as our modules do (there are examples in that tutorial you linked to), and populate the public/css
and public/js
subdirectories of your module with .less and .js files.在大多数情况下,您可以调用
pushAsset
,就像我们的模块一样(您链接到的教程中有示例),并使用 .less 和 .js 文件填充模块的public/css
和public/js
子目录。
But for this case, since the URL is external and requires query parameters, there isn't really a baked-in solution.但是对于这种情况,由于 URL 是外部的并且需要查询参数,因此并没有真正的内置解决方案。 After all, a large part of the point of Apostrophe's asset-pushing mechanism is minification, which really doesn't apply here.
毕竟,Apostrophe 的资产推送机制的很大一部分重点是缩小,这在这里并不适用。 Loading assets externally is... well... external.
从外部加载资产是......好吧......外部。
So a block in your outerLayout makes perfect sense for your scenario.因此,outerLayout 中的块对您的场景非常有意义。
Hope this is helpful!希望这是有帮助的!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.