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
Community showcase
Posted Tuesday in Featured Groups

Tuesday tips & tricks: What is the Atlassian Community?

It's officially Tuesday, which means it's officially time for another tip to help you better navigate this space we call the Atlassian Community. 😄 I got a great question from community member, Sa...

119 views 6 8
View post

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