Conditional dynamic display of macros - possible?
Asked by Sven:

Hello,  
I'm searching for a way to do in confluence something like this:  
IF checkbox xyz is checked then  
display "{livesearch} limited to current space"  
else  
display "{livesearch}"

Is something like this possible?  
I imagine I could get this done with some "jquery-magic" (and the html-macro), but perhaps there a existing (user-)macros for this kind of task?

Thanks in advance for any hint!

Bye  
Sven


Answers:
author: Bob Swift (personal)
body: You can use the [Run Plugin](https://studio.plugins.atlassian.com/wiki/display/RUN) to do things like this. In more complex cases, you may need some some additional logic using [Confluence Script Plugin](https://studio.plugins.atlassian.com/wiki/display/SCRP) or other similar macros.

comments: author: Sven
body: wow, that looks powerful, I'll try this out! Thanks!

(although I've stepped some time ago through all confluence plugins, I've missed this one ;-)


author: Sven
body: could you give me a quick hint:

I try:

```
{run:autorun=true|replace=year:::checkbox::SEO:SEO} livesearch:spaceKey=$year{run}
```

...and when I click on the link, it replaces the correct word but in '' (which cases it to fail) - Why?

livesearch:spaceKey='SEO'

(I will add the {livesearch:spaceKey='SEO'} later...


author: Bob Swift (personal)
body: Checkbox is a multi-select control, so use **suppressQuote=true** to avoid in your case - see [Run macro](https://studio.plugins.atlassian.com/wiki/display/RUN/Run+macro "Run macro") documentation.


author: Sven
body: Thanks for the answer!

I'm a developer, and I was digging through the documentation, but I didn't figure this out... Are there somewhere more samples than that:

<https://studio.plugins.atlassian.com/wiki/display/RUN/Release+notes+2.0>

Anyway, I've formulated it the other way round in the meantime and it's working well:

```
{run:autorun=true|titleRun=Go|replace=space:SEO:search everywhere:checkbox:30:'':''} {livesearch:spaceKey=$space}{run}
```

And I added some jQuery-Magic to make an Form-Submit on checking the checkbox:

(must go to CustomHTML in head):

```
&lt;script&gt;jQuery(document).ready(function() {    //jQuery('input[type="button"][value="Go"]').hide();     jQuery('input[name=run_1_space]').click( function(e){         jQuery(this).closest('form').submit();     });	});&lt;/script&gt;
```

This way I've added even some "ajax" ;-)

Now... the only thing I'm struggling with is:

- to get rid of the tables in your run-macro

- to get rid of the "submit"-Button

I've tried to do it by jquery, but the table in the run-macro has no "custom class" (just confluence-table) and the submit-button has no custom id...

...or did I miss some settings in your incredible useful macro?


author: Bob Swift (personal)
body: Look through the parameters on the documentation page [Run macro](https://studio.plugins.atlassian.com/wiki/display/RUN/Run+macro "Run macro") , for instance - hideRun, hideColumnHeadings, parameterInput.


author: Benoit LOUZAS
body: Hello,

I would like to do something similar to the feature you've explained.

I have 2 documents (template A, template B) with check lists that are almost the same at 90%.

I want to create one document/template, with info from both A and B, so I need to do something like Sven did

IF checkbox xyz is checked then  
display "paragraph specific A"  
else  
display "paragraph specific B"

but the link you gave, for the Run Macro and Script Plugin are not working. Is this not supported anymore?

Thanks in advance

Benoit


author: Bob Swift (personal)
body: Checkbox is a multi-select control, so use **suppressQuote=true** to avoid in your case - see [Run macro](https://studio.plugins.atlassian.com/wiki/display/RUN/Run+macro "Run macro") documentation.

comments: author: Sven
body: Thanks for the answer!

I'm a developer, and I was digging through the documentation, but I didn't figure this out... Are there somewhere more samples than that:

<https://studio.plugins.atlassian.com/wiki/display/RUN/Release+notes+2.0>

Anyway, I've formulated it the other way round in the meantime and it's working well:

```
{run:autorun=true|titleRun=Go|replace=space:SEO:search everywhere:checkbox:30:'':''} {livesearch:spaceKey=$space}{run}
```

And I added some jQuery-Magic to make an Form-Submit on checking the checkbox:

(must go to CustomHTML in head):

```
&lt;script&gt;jQuery(document).ready(function() {    //jQuery('input[type="button"][value="Go"]').hide();     jQuery('input[name=run_1_space]').click( function(e){         jQuery(this).closest('form').submit();     });	});&lt;/script&gt;
```

This way I've added even some "ajax" ;-)

Now... the only thing I'm struggling with is:

- to get rid of the tables in your run-macro

- to get rid of the "submit"-Button

I've tried to do it by jquery, but the table in the run-macro has no "custom class" (just confluence-table) and the submit-button has no custom id...

...or did I miss some settings in your incredible useful macro?


Tags: condition

forms

macro

user-macro