如何将外部 JavaScript 或 CSS 文件添加到我们的 Tridion 页面? [英] How to add external JavaScript or CSS files to our Tridion page?

查看:18
本文介绍了如何将外部 JavaScript 或 CSS 文件添加到我们的 Tridion 页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个外部 JavaScript 和一个 CSS 文件.我不知道如何将此文件添加到我的页面.我正在将 DWT TBBs 用于 CT 和 PT.

我正在我的页面 TBB 中编写内部 CSS 以暂时获取输出.但我不知道如何实现 JavaScript.有人可以帮助我吗?

我应该将这些文件作为组件并将它们呈现在我的页面上吗?这是正确的方法吗?如果是,请告诉我要遵循的步骤.

解决方案

这是一个广泛讨论的话题,我将尝试概述各种可能性:

  1. 创建 CSS &JS 作为二进制组件,从 DWT 模板链接到这些
  2. 创建 CSS &JS 作为二进制组件,作为 DCP 发布到服务器,通过 url 链接到二进制
  3. 创建 CSS &JS 作为 Text 组件,放置在页面中,发布到服务器,将 url 链接到页面
  4. 复制 CSS &JS 到交付服务器(不是 Tridion),使用 url 链接到 css &js

选项 #1 是最简单的,但也有不少缺点.

  • 使用您需要的 CSS 和 JS 文件在 Tridion 中创建多媒体组件.
  • 记下 URI,然后在 DWT 中使用类似的内容:

<script src="tcm:27-2763" type="text/javascript"></script>

如果您的模板使用默认完成操作构建块,则 Tridion 将解析对这些二进制文件的引用并将其与您的页面一起发布.这会产生副作用,即这些二进制文件将与使用相同模板的所有页面一起发布.

选项#2 要求您编写一个动态组件模板,可能还有一些代码来确定文件发布到的位置.这更符合我通常实施的做法,但目前我不建议您这样做.随着您对 Tridion 知识的增长,您会感到很自在,可以自己完成这项工作.使用此选项,您可以将 CSS/JS 文件发布到给定位置,然后在 DWT 中使用引用,而不是使用 TCM URI(如上所述)将使用文件发布到的 URL.

选项#3 要求您创建一个代码组件和模板",这意味着一个简单的架构,只有一个大文本字段(不是富文本),可以在其中复制/粘贴 CSS 或 JS 的内容.然后编写一个简单的组件模板,该模板将按原样输出内容.类似于 @@Fields.Code@@.最后,您创建 2 个页面模板(一个扩展名为 .js,另一个扩展名为 .css),只有一个 DW 模板:

@@RenderComponentPresentation()@@<!-- TemplateEndRepeat -->

最后,同样重要的是(有很多方法可以给这只猫剥皮)你可以将这些 CSS/JS 文件直接放在你的网络服务器上,然后在你的 DWT 中添加一个链接到这些文件可用的 URL.

希望这能给你一些选择.请记住,应在页面模板级别(最好在页面的 部分)而不是在组件模板中包含 CSS/JS.

I have an external JavaScript and a CSS file . I am not getting the idea how to add this file to my page. I am using DWT TBBs for both CTs and PTs.

I am writing internal CSS in my page TBB for getting the output for the time being. but I am not getting how to implement JavaScript. Can somebody help me?

Should I make these file as component and render them on my page? Is this the correct way? If yes, please tell me the steps to be followed.

解决方案

This is a topic for wide discussion, I'll try to outline the various possibilities:

  1. Create CSS & JS as Binary Components, link to these from DWT template
  2. Create CSS & JS as Binary Components, publish to Server as DCP, link with url to binary
  3. Create CSS & JS as Text components, place in page, publish to server, link url to page
  4. Copy CSS & JS to delivery server (not Tridion), link with url to css & js

Option #1 is the easiest, with quite a few drawbacks.

  • Create Multimedia Components in Tridion with the CSS and JS files you need.
  • Note down the URIs then use something like this in your DWT:

<link href="tcm:27-2762" rel="stylesheet" type="text/css" />
<script src="tcm:27-2763" type="text/javascript"></script>

If your template uses the Default Finish Actions Building Block, then Tridion will resolve the references to those binaries and publish it with your page. This has the side-effect that these binaries would be published with ALL pages that use the same template.

Option #2 requires you to write a Dynamic Component Template, possibly with some code to determine where files get published to. This is more in line with what I normally implement, but at this point in time I would not recommend that you do this. As you grow Tridion knowledge, you'll feel comfortable enough to do this by yourself. Using this option you can then publish the CSS/JS files to a given location, then use references in your DWT that instead of using the TCM URIs (as above) would use the URL that the files get published to.

Option #3 requires you to create a "code component & template", meaning a simple schema with just one large text field (not rich text) where copy/paste the content of your CSS or JS. Then write a simple component template that will just output the content as is. Something like @@Fields.Code@@. Lastly you create 2 page templates (one with extension .js, the other with extension .css) with only one DW Template:

<!-- TemplateBeginRepeat name="Components" -->
@@RenderComponentPresentation()@@
<!-- TemplateEndRepeat -->

Last, and definitely not least (there's many ways to skin this cat) you could just place these CSS/JS files directly on your webserver, and add a link in your DWT to the URLs where these files are available.

Hope this gives you some options. Remember that including CSS/JS should be done at Page Template Level (ideally in the <head> portion of your page), and not in your Component Template.

这篇关于如何将外部 JavaScript 或 CSS 文件添加到我们的 Tridion 页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆