javascript - 如何在velocity模板中引用css和js?

标签 javascript css velocity confluence

我正在尝试访问我的 css 和 js 文件(位于 resources/css/stylesheet.css 和 ../js/..),但我不确定如何访问。

我已经尝试在 和 标签之间使用 $webResourceManager.requireResource(xxx:xxx) ,但它只是在网页上打印 $webRes... 。我还在头部使用了#requireResource(xxx:xxx)。它没有打印在页面上,但也没有用。

atlassian-plugin.xml

<web-resource key="statPlugin-resources" name="statPlugin Web Resources">
        <dependency>com.atlassian.auiplugin:ajs</dependency>

        <resource type="download" name="statPlugin.css" location="/css/statPlugin.css"/>
        <resource type="download" name="statPlugin.js" location="/js/statPlugin.js"/>
        <resource type="download" name="images/" location="/images"/>
        <resource type="velocity" name="test" location="/templates/test.vm"/>

        <context>statPlugin</context>
</web-resource>

在 page.vm 中

<head>
    <title>Stat Plugin Configuration</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>

</head>

$webResourceManager.requireResource("com.tdk.plugin:statPlugin-resources")

<body>
...
</body>

Error message: Uncaught ReferenceError: addCard is not defined at HTMLButtonElement.onclick (stat-config:33)

所以找不到js文件。

最佳答案

答案很简单,但很难找到,因为文档已过时。在我的第一次尝试中,我尝试使用不再被弃用的 WebresourceManager。你必须使用 ConfluenceWebresourceManager。您可以在使用组件导入时访问它。

为您的 Velocity 插件提供您必须使用的资源管理器

context.put("confluenceWebResourceManager",confluenceWebresourceManager");

在您的 servlet 的 doGet 或 doPost 中。

在模板本身中,您必须编写以下内容:

<head>
...
</head>
    $confluenceWebResourceManager.requireResource("com.company.plugin.pluginName:pluginName-resources")
<body>
...

关于javascript - 如何在velocity模板中引用css和js?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57037535/

相关文章:

html - 使用 "SVG polygon"悬停状态在 "SVG"之后淡入 div

javascript - 如何将js文件包含到Velocity模板中?

jquery - 如何使用其他页面的 CSS?

c++ - sfml 2.0 中的速度和耗时

javascript - 如何找到哪个 javascript 代码触发了 ajax?

javascript - node和node中间件中的 'req'和 'res'参数是什么?

javascript - 尝试将 SimpleBar 导入 Angular 2 应用程序时,X 不是构造函数

javascript - Leaflet 在使用 geoJson 时交换坐标

在 WordPress 的 PDF 文件下载链接中检测到 HTML 恶意文件

html - 前一个同级选择器的多种颜色