how to create a "add/remove favourite" button ??

I need to create a favourite button, how to know if a page or a user is favourite ??

please help.. thnx ! :D

3 answers

in velocity, you could use this:

#if($helper.page.isFavourite($action.remoteUser))
	<a href="$req.contextPath/labels/removefavourite.action?entityId=$helper.page.id&#url_xsrfToken()"  alt-title="$action.getText('favourite.add.page')" title="$action.getText('favourite.remove.page')"   class="fav-toggle active aui-button" >
		remove
	</a>
#else
	<a href="$req.contextPath/labels/addfavourite.action?entityId=$helper.page.id&#url_xsrfToken()"   alt-title="$action.getText('favourite.remove.page')" title="$action.getText('favourite.add.page')"   class="fav-toggle aui-button " >
		add
	</a>

#end

similar in java ;-)

Thanks for the code snippet, Oliver, it helped me greatly. However, I had to make some minor adjustments:

#if($content.isFavourite($action.remoteUser))
    <a href="$req.contextPath/labels/removefavourite.action?entityId=$content.getIdAsString()&#url_xsrfToken()"  alt-title="$action.getText('favourite.add.page')" title="$action.getText('favourite.remove.page')"   class="fav-toggle aui-button">
        remove
    </a>
#else
    <a href="$req.contextPath/labels/addfavourite.action?entityId=$content.getIdAsString()&#url_xsrfToken()"   alt-title="$action.getText('favourite.remove.page')" title="$action.getText('favourite.add.page')"   class="fav-toggle aui-button">
        add
    </a>
 
#end

Oliver's code worked for me.  Thanks!

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published 8 hours ago in Jira Software

How large do you think Jira Software can grow?

Hi Atlassian Community! My name is Shana, and I’m on the Jira Software team. One of the many reasons this Community exists is to connect you to others on similar product journeys or with comparabl...

103 views 4 5
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