简体   繁体   English

从自定义 Shopify 应用程序将 JavaScript 添加到 Shopify 模板

[英]Adding JavaScript to Shopify templates from an Custom Shopify App

Does anyone know if it's possible with the Shopify API to inject JavaScript code into Shopify template files like you can do using the Script Tags API with JavaScript files.有谁知道是否可以使用 Shopify API 将 JavaScript 代码注入 Shopify 模板文件,就像使用带有 JavaScript 文件的脚本标签 API 一样。

My goal is to have the app hit the server, get JavaScript code like <script type="text/javascript">console.log('App is running')</script> and inject that into every template page.我的目标是让应用程序访问服务器,获取像<script type="text/javascript">console.log('App is running')</script>这样的 JavaScript 代码并将其注入每个模板页面。

That way you wouldn't need to edit the themes template files.这样您就不需要编辑主题模板文件。

I'm not looking for recommendations for books, tools, software libraries, and more.我不是在寻找书籍、工具、软件库等方面的建议。 I want to know if it's possible to do this with the Shopify API.我想知道是否可以使用 Shopify API 做到这一点。

The short answer is yes.简短的回答是肯定的。 You can inject your Javascript into theme templates, because they are just that.您可以将 Javascript 注入主题模板,因为它们就是这样。 Templates.模板。 Adding code to them is not difficult.向它们添加代码并不困难。 You edit them with the API.您可以使用 API 编辑它们。

But if you did that, you'd be mangling the theme.但如果你这样做,你就会破坏主题。 If someone deleted your App, that mangling would remain.如果有人删除了您的应用程序,则该修改将保留。

So you do not do that.所以你不要那样做。 You get to stick with Script Tags.您可以坚持使用脚本标签。

You should re-think your strategy.你应该重新考虑你的策略。 Stick to what works, cleanly.坚持有效的方法,干净利落。 I am pretty sure Shopify would hammer ban you anyway, but still, at least you know now.我很确定 Shopify 无论如何都会禁止你,但至少你现在知道了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM