Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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

Why is the GetExcerpt method erratic inside a User Macro?

I've been trying to use the GetExcerpt() method inside a user macro and get some odd behavior. If the Excerpt macro on a page has just a few words, the method picks up some more content that is below (not within) the Excerpt macro. If the macro has a long paragraph, the GetExcerpt() method seems to truncate after just a 100 or so characters. All this seems very odd - one would expect that the method would do as its name implies and no more and no less - just provide the content that is bound within the Excerpt.

BTW - I'm using Confluence 5.1.4 running on a Windows Server with MySQL.

To illustrate, I wrote this simple User Macro called myexample2:

## @noparams

#set( $myexcerpt =  $content.getExcerpt().replaceAll('"', '"'))

<h2>Result of Get Excerpt Method</h2>

<p>$myexcerpt</p>

Here is the code behind a simple page that illustrates the problem with a short Excerpt:

<ac:macro ac:name="excerpt">
  <ac:parameter ac:name="atlassian-macro-output-type">BLOCK</ac:parameter>
  <ac:rich-text-body>
    <p>Foo bar</p>
  </ac:rich-text-body>
</ac:macro>
<h2>Next Header</h2>
<p>And some more stuff that shouldn't show up</p>
<p> </p>
<p>
  <ac:macro ac:name="myexample2"/>
</p>

And here is a screen shot of the results - notice that the user macro incorrectly brings in content outside of the Excerpt:

Here is the code behind a copy of the same page only with more text in the Excerpt:

<ac:macro ac:name="excerpt">
  <ac:parameter ac:name="atlassian-macro-output-type">BLOCK</ac:parameter>
  <ac:rich-text-body>
    <p>Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.</p>
    <p>Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived and so dedicated, can long endure. We are met on a great battle-field of that war. We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live. It is altogether fitting and proper that we should do this.</p>
    <p>But, in a larger sense, we can not dedicate -- we can not consecrate -- we can not hallow -- this ground. The brave men, living and dead, who struggled here, have consecrated it, far above our poor power to add or detract. The world will little note, nor long remember what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to be here dedicated to the great task remaining before us -- that from these honored dead we take increased devotion to that cause for which they gave the last full measure of devotion -- that we here highly resolve that these dead shall not have died in vain -- that this nation, under God, shall have a new birth of freedom -- and that government of the people, by the people, for the people, shall not perish from the earth.</p>
  </ac:rich-text-body>
</ac:macro>
<h2>Next Header</h2>
<p>And some more stuff that shouldn't show up</p>
<p> </p>
<p>
  <ac:macro ac:name="myexample2"/>
</p>

And here is a screen shot of the results - notice that it truncates most of the excerpt:

So..., I'm sure I'm doing something wrong. Can someone help?

Thanks!

1 answer

1 accepted

2 votes
Answer accepted

Wow - do I get extra karma points for stumping the wizkids? Well, I discovered a work-a-round solution which will probably stop working one sad day when Atlassian finally destroys the last remnants of wiki markup. Personally, I hope that day never comes because I believe wiki markup is a good thing, not a bad thing. So here is my work-a-round to the getExcerpt method not working properly:

## @noparams

#set($macroFinal = "{excerpt-include:" + $content.getTitle() + "|nopanel=true}")
#set( $myexcerpt =  $action.getHelper().renderConfluenceMacro($macroFinal).replaceAll('"', '"')   )

<h2>Result of renderConfluenceMacro Method</h2>

<p>$myexcerpt</p>

<h2>Result of getExcerpt Method without Set</h2>

<p>$content.getExcerpt()</p>

All this does is use the renderConfluenceMacro method on the regular {excerpt-include} macro. Pretty slick trick that works perfect for my needs and hopefully Atlassian won't take this ability away before fixing the defective getExcerpt method. In the meantime, I'll take my 35 karma point reward and work on the next fun issue!

Thanks for taking the effort to answer your own question, saved me quite some time.
I experienced exactly the same behaviour, now 6(!) years. And I can confirm that your workaround still works like a charm.

Thanks again.

Suggest an answer

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

What do you think is the most *delightful* Confluence feature? Comment for a prize!

- Create your own custom emoji 🔥 - "Shake for Feedback" on mobile 📱 - An endless supply of GIFs via GIPHY 🤩 Is there anything quite as nice as a pleasant surprise? Comment below with what...

454 views 24 9
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