Confluence Blueprints: How to display the list of existing macros in the dialog-page ?

Hi,

I'm trying to develop a Blueprint that will include in the rendered page a macro choosen by the user in a list or by auto-completion

I know how to do it in Java (using com.atlassian.confluence.macro.browser.MacroMetadataManager)

But I don't know how to create a custom list in soy template with dynamic content (provided by a Java class ?)

I spent a lot of time on this forum:

1) I tried to implement com.atlassian.soy.renderer.SoyServerFunction as describe here: https://answers.atlassian.com/questions/89158/getting-a-soy-function-to-work-in-a-stash-plugin

  • Content of my .soy template
    {namespace MyPlugin.Blueprints.Simple}
    
    {template .macros}
    	Hello
    	{SoyMacrosFunction()}
    {/template}
  • but it always return error: Uncaught Error: atlassian-plugin.xml blueprint wizard points to a non-existent Soy template 'MyPlugin.Blueprints.Simple.loop'.
  • If I remove instruction {SoyMacrosFunction()}, the template works

2) I tried to use classes autocomplete-multiselect in my soy template. It doesn't work

Any adivse would be much appreciated.
Cheers,
Xavier

2 answers

1 accepted

1 vote
Accepted answer

My previous comment was not recognized by the Atlassian email robot. So I answer to my own question:

I'm now able to display the list of existing macros in the dialog-page of a Blueprint. But I used a REST API in conjunction with javascript hook as described in my comment. I was not able to implement a SoyMacroFunction

Hi Xavier,

please try to add a SoyDoc before your template:

{namespace MyPlugin.Blueprints.Simple}
/**
*  This is a SoyDoc example
*/
{template .macros}
    Hello
    {SoyMacrosFunction()}
{/template}

See: https://developer.atlassian.com/display/CONFDEV/Writing+Soy+Templates+in+Your+Plugin (For templates that need parameters, these must be declared in JavaDoc style immediately before the template)

I hope I could help.

Cheers,

Raffy.

There is already a SoyDoc in my .soy file but I didn't copy it my this example.

Anyway, I changed the way of doing:

I created a REST API based on this tutorial to retrieve all installed Confluence macros and I added the following code in the javascript file associated to my blueprint based on this tutorial

Confluence.Blueprint.setWizard('com.xxx.confluence.macrodoc:macro-documentation-blueprint-item', function(wizard) {
    wizard.on('post-render.macroDocumentation', function(e, state) {
	    fetchAndDisplayMacros = function() {
	        $macrosContainer = $("#macroName");
	        $macrosContainer.append("<option value='Loading'> Loading...</option>");
	        $.ajax({
	            type: 'GET',
	            url: AJS.contextPath() + '/rest/macro/1.0/macros',
	            contentType:'application/json'
	        }).done(function(macros) {
	        	$macrosContainer.empty();
	            for (var i = 0; i < macros.length; ++i) {
	            	var macro = macros[i];
	                $macrosContainer.append("<option value='" + macro.macroName+ "'>" + macro.titleText + "</option>");
	            }
	            if ($macrosContainer.find("option").length == 0) {
	                $macrosContainer.html("<p>No macro have been defined.</p>");
	            }
	        }).fail(function() {
	            clearMessages();
	            AJS.messages.error("#aui-message-bar", {
	               body: "<p>Failed to fetch macros.</p>",
	               closeable: true,
	               shadowed: true
	            });
	        });
	    };
	
	    // Fetch macros on page load
	    fetchAndDisplayMacros();
   });
});
Now it works perfectly but the use of SoyFunction still doesn't work !!

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Monday in Confluence

Organizing your space just got easier - Page Tree Drag & Drop is here

Hi Community! I’m Elaine, Confluence Product Manager. You may have read my earlier post about page tree in space navigation sidebar. I'm excited to share another improvement that helps you organize ...

159 views 3 5
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you