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

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](/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


Answers:
author: Xavier Arques
body: 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


author: dy raffy
body: 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.

comments: author: Xavier Arques
body: 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](https://developer.atlassian.com/display/CONFDEV/Creating+a+Confluence+Task+Plugin+with+REST "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](https://developer.atlassian.com/display/CONFDEV/Javascript+API+for+blueprint+wizards "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("&lt;option value='Loading'&gt; Loading...&lt;/option&gt;");	        $.ajax({	            type: 'GET',	            url: AJS.contextPath() + '/rest/macro/1.0/macros',	            contentType:'application/json'	        }).done(function(macros) {	        	$macrosContainer.empty();	            for (var i = 0; i &lt; macros.length; ++i) {	            	var macro = macros[i];	                $macrosContainer.append("&lt;option value='" + macro.macroName+ "'&gt;" + macro.titleText + "&lt;/option&gt;");	            }	            if ($macrosContainer.find("option").length == 0) {	                $macrosContainer.html("&lt;p&gt;No macro have been defined.&lt;/p&gt;");	            }	        }).fail(function() {	            clearMessages();	            AJS.messages.error("#aui-message-bar", {	               body: "&lt;p&gt;Failed to fetch macros.&lt;/p&gt;",	               closeable: true,	               shadowed: true	            });	        });	    };		    // Fetch macros on page load	    fetchAndDisplayMacros();   });});
```

```
Now it works perfectly but the use of SoyFunction still doesn't work !!
```


Tags: blueprint

confluence-app

soy-templates