It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Creating HTML macro that will search in multiple defined wiki pages

Hello,

I have a few wiki spaces and would like to create a search bar using the HTML macro that will allow me to search within only the few spaces I've defined. I'm not handy with HTML and would like some help with an HTML macro that will allow me to do this. I know the newer version of Confluence has this ability but my org will not update to a new version.


Thank you!

1 comment

DPK_J Community Leader Aug 23, 2019

Here is sample you can use and start your work.

It contain a simple html form with text field, and when you submit this form search result page is opened.

There is array called 'SPACES_KEY' in which you can provide all spaces you want to search with this particular form.

 

<div>
<form id="space-search" method="GET">
<input type="text" name="query" id="search-query"/>
<input type="submit" value="Search" />
</form>
<script>
AJS.toInit(function () {
var SPACES_KEY = ['CM']; //list all space you want to search in this array
var $ = AJS.$;

$('#space-search').submit(function (e) {
e.preventDefault();
var q = $('#search-query').val();
var query = 'siteSearch ~ "' + q + '" AND space in (' + SPACES_KEY.join(",") + ')';

window.location = 'dosearchsite.action?cql=' + encodeURI(query); //open new page with search results

return false;
});
});
</script>

</div>

This worked perfectly, thank you!

Comment

Log in or Sign up to comment
TAGS
Community showcase
Posted in Confluence

What project did you transition or start on Confluence with the shift to remote work?

It’s been great to hear from fellow users over the last few weeks about the best tips and fun moments you’ve had working on Confluence since the transition to working remote. I’d love to keep the c...

397 views 11 11
Join discussion

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you