Use macros (such as search) with page template

Hello everyone

I was wondering if it's possible to use the search macro on a page template.

I have the following need for it:

Whenever I create a space, i need a home page with a search macro for the specific space. The search macro need a space key in order for it to search a specific space.

Can I somehow get it to automatically set the space key, to the space the page is being created in.

For instance, I have a space called TestSpace, with the key TEST. Can I then get the template with the search macro to set the space key to TEST?

2 answers

0 votes

I don't think you can have dynamic variables like this in a page template.

There may be another way to do it though (Confluence 5.8+), the search macro that you are using may be able to be replaced with one of the new cql based macros.

The advanced search macro and all the other CQL based search macros all support a "Current Space" filter allowing you to find content in the current space.

Another option will be to consider replacing your page Template with a blueprints which will allow a much richer and more dynamic way to populate the pages.  Look here: https://confluence.atlassian.com/display/DOC/Blueprints

0 votes
Davin Studer Community Champion Aug 21, 2015

You could wrap the livesearch macro in a user macro that will supply the space key for you. The below user macro gives you all of the livesearch macro parameters except the space key. It will auto insert that one.

Macro Name:
space_livesearch 

Macro Title:
Space Livesearch 

Description:
Embeds a search box into your Confluence page to show search results as you type. 

Macro Body Processing:
No macro body

Template:

## Developed by: Davin Studer
## Date created: 08/21/2015
 
## @param Labels:title=Restrict to label(s)|type=string|required=false|desc=A comma separated list of labels to filter the search by
## @param Size:title=Size|type=enum|enumValues=medium,large|default=medium|desc=
## @param Placeholder:title=Placeholder text|type=string|required=false|desc=
## @param Content:title=Content type to include in search|type=enum|enumValues=all,page,blogpost,comment,spacedesc|default=all|desc=
## @param Additional:title=Additional information|type=enum|enumValues=none,space name,page excerpt|default=space name|desc=
 
<ac:structured-macro ac:name="livesearch">
    <ac:parameter ac:name="additional">$!paramAdditional</ac:parameter>
    <ac:parameter ac:name="placeholder">$!paramPlaceholder</ac:parameter>
    <ac:parameter ac:name="labels">$!paramLabels</ac:parameter>
    <ac:parameter ac:name="spaceKey">
        <ri:space ri:space-key="$content.spaceKey"/>
    </ac:parameter>
    <ac:parameter ac:name="type">$!paramContent</ac:parameter>
    <ac:parameter ac:name="size">$!paramSize</ac:parameter>
</ac:structured-macro>

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 29, 2018 in New to Confluence

How to use Confluence Cloud for stakeholder management

Most of us don’t need much convincing that stakeholder management is important. It just makes sense that keeping everyone in-the-know on projects and assigning clearly defined roles is key to having ...

1,145 views 4 6
Read article

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