Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

requireResource macro not working

Tobias Torkler February 20, 2012

I am writing a report plugin for Jira 4.4.

<?xml version="1.0" encoding="UTF-8"?>

<atlassian-plugin key="de.fact.jira.plugins.reporting" name="FACT Reporting" plugins-version="2">
  <plugin-info>
    <description>FACT Reporting</description>
    <version>1.0</version>
    <vendor name="FACT" />
  </plugin-info>
  <web-resource key="styles" name="FACT Reporting Styles" i18n-name-key="styles.name">
    <resource type="download" name="styles.css" location="/templates/reports/styles.css" />
  </web-resource>
  <report key="release-report" name="FACT Release Report" i18n-name-key="release-report.name" class="de.fact.jira.plugins.reports.ReleaseReport">
    <label key="release-report.label" />
    <description key="release-report.description" />
    <resource name="view" type="velocity" location="/templates/reports/release-report/view.vm" />
    <resource name="i18n" type="i18n" location="ReleaseReport" />
    <properties>
      ...
    </properties>
  </report>
  <resource type="i18n" name="i18n" location="atlassian-plugin" />
</atlassian-plugin>

In my Velocity template I use the requireResource macro to include the resources into the header. 

#requireResource("de.fact.jira.plugins.reporting:styles")

It does not do anything. Do I have to inlcude this macro in my template or should it work out of the box? What macros are available by default?

4 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

3 votes
Answer accepted
Sara ak
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 21, 2013

maybe this helps:

in your atlassian-plugin.xml define your resources:

<web-resource key="sth-resources" name="sth Web Resources">
<dependency>com.atlassian.auiplugin:ajs</dependency>
<resource type="download" key="sth.css" name="sth.css"
location="/css/sth.css" />
<resource type="download" name="sth.js" location="/js/v.js" />
<resource type="download" name="images/" location="/images" />
<context>STH CONTEXT</context>
</web-resource>

in your velocity template :

$webResourceManager.requireResourcesForContext("STH CONTEXT")

you can pass webResourceManager to template using:

params.put("webResourceManager", ComponentAccessor.getComponentOfType(WebResourceManager.class));
Ambar Patil May 16, 2016

I have same problem and tried both way $webResourceManager.requireResourcesForContext("my-context") and

#requireResourcesForContext("my-context")

but nothing works for me. I have one css which I wants to include in my macro, I tried by both of this way but no css will be applied to macro.

 

myMacro.vm

#requireResourcesForContext("nc-display-confluence-log")

<h3>Atlassian Confluence Log</h3>
#if(${data.getGeneratedLog()})
<div class="log-window" >
${data.getGeneratedLog()}
</div>
#else
<h3>No Log generated yet.</h3>
#end

 

and atlassian-plugin.xml includes, 

 

<web-resource key="ncDisplayConfluenceLog-resources" name="ncDisplayConfluenceLog Web Resources">
<dependency>com.atlassian.auiplugin:ajs</dependency>
<resource type="download" name="ncDisplayConfluenceLog.css"
 location="/com/myCompany/confluence/ndcl/css/ncDisplayConfluenceLog.css"/>
    <resource type="download" name="ncDisplayConfluenceLog.js"
 location="/com/myCompany/confluence/ndcl/js/ncDisplayConfluenceLog.js"/>
    <resource type="download" name="images/" location="/com/myCompany/confluence/ndcl/images"/>
<context>my-context</context>
</web-resource>

Any suggestion on it.

 

0 votes
ramin mirahmadi October 7, 2013

hi.

after i tested all suggestions i found that i can load my javascript and css file with this code in my velocity(vm) files.

&lt;link type="text/css" href="$req.contextPath/download/resources/com.jira.plugins.persiandatepicker:resources/jquery-ui-1.8.14.css" rel="stylesheet" /&gt;

&lt;script type="text/javascript" src="$req.contextPath/download/resources/com.jira.plugins.persiandatepicker:resources/jquery.ui.datepicker-cc.all.min.js"&gt;&lt;/script&gt;
Ajay _view26_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 3, 2018

Why is 

requireResourcesForContext

not woking ? 

0 votes
ramin mirahmadi September 21, 2013

hi. i have the same problem

&lt;web-resource key="resources" name="Resources"&gt;
&lt;dependency&gt;com.atlassian.auiplugin:jquery&lt;/dependency&gt;
&lt;resource type="download" name="jqueryuidatepicker" location="templates/com/pooya/jira/plugins/persiandatepicker/scripts/jquery.ui.datepicker-cc.all.min.js"/&gt;
&lt;resource type="download" name="images/" location="templates/com/pooya/jira/plugins/persiandatepicker/styles/images"/&gt;
&lt;resource type="download" name="jqueryuicss" location="templates/com/pooya/jira/plugins/persiandatepicker/styles/jquery-ui-1.8.14.css"&gt;
&lt;property key="content-type" value="text/css"/&gt;
&lt;/resource&gt;
&lt;context&gt;jira.general&lt;/context&gt;
&lt;context&gt;atl.general&lt;/context&gt;
&lt;context&gt;atl.admin&lt;/context&gt;
&lt;/web-resource&gt;

 

i used #requireResource and #requireResourcesForContext but both of them didn't work.

after run the project i see #requireResource(....) id create issue pop-up in dashboard

 

please help me how to use my javascript function in edit velocity file of my plugin

0 votes
tier-0 grump
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 22, 2012

It should work out of the box - have you tried it with the #includeResources() macro to ensure they are included, so do

#requireResource("de.fact.jira.plugins.reporting:styles")
#includeResources()

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events