Wrtting Confluence theme using Java code

Hi,

I am creating confluence theme using tutorial https://developer.atlassian.com/display/CONFDEV/Plugin+Tutorial+-+Writing+a+Confluence+Theme. In my case, I am changing page.vmd to have my own page layout and design. There is $body object in page.vmd. I need to change it to have my own content. How can I change. It would be great if I could change it in Java code.

Can anyone help in that regard.

Thanks

Best Regards,

Muhammad Ali

1 answer

0 vote

I don't think you've grasped what you're asking here.

The $body contains the *body* of the page that Confluence is going to draw for the user. You don't mess with that in a theme because whatever you do will affect every page using that theme, and the $body is quite simply "what the users have put on the page". Themes are for altering the surroundings, the css, and the behaviour of a space, NOT for hacking the body.

You can't really do it in Java even if it were the right thing to do. By the time $body becomes available, Confluence has already done a load of formatting work on it, and it's coming out via page.vmd. If you wanted to amend the content in Java, then you'd have to provide java mechanisms to feed it back to the java, process it and chuck it back out in the .vmd, which is a lot of effort and I'm 99.99% certain, not what you actually want.

So, all of this begs the obvious question - why do you think you want to amend $body? (And why in a theme?) Rather than tell us what you think you want to do on a technical level, could you explain what you actually want for the end user?

Thanks Nic for quick reply.

Well, let me explain you the whole picture. I am setuping confluence for my company and there is requirement that whenever some confluence user creates his personal space, our own build theme or layout or template should be used in building that personal space so that all personal spaces should remain constant (similar page content and style). There is another requirement link with this is that I need extract some text content from different user's personal space and display them on some other page. According to me, it requires that personal space must contain some unique id tags (div) for all users which could be searched later on to find desired text.

I have discovered that only newly created theme can appear as an option when one tries to create personal space. Therefore, I asked you about changing $body. But If you know some beter option than I will be glad to use.

Thanks

Best Regards,

Muhammad

Ok, that makes sense.

>whenever some confluence user creates his personal space, our own build theme or layout or template should be used in building that personal space so that all personal spaces should remain constant (similar page content and style).

That's exactly what themes are for, if I've understood correctly. Basically, you need every personal space to use the same theme so that they all have the same look and feel, layout and so-on. The problem I can see here is that people are free to pick other themes if they want to override the default. The trick there is to disable all the themes that you don't want people to use. If you narrow it down to a single theme, then your entire Confluence installation will be totally consistent and they won't be able to swap.

None of that has anything to do with the content of pages within the space, it's all about the layout. Hence why I picked up on the $body thing - there's absolutely no need for you to even think about the content when you're messing with the layout - content and theme are totally separate.

>I need extract some text content from different user's personal space and display them on some other page

Right, now this is totally separate. You can't force this on your users by hacking the theme. In fact, you'll never be able to force it on them because they're always going to be free to edit the content of their spaces.

Extracting data is probably quite easy - you can use things like the "excerpt" macro to define chunks of a page to extract the data and accumulate it elsewhere (the standard excerpt macro needs to be in the same space, but a bit of coding should get you something a bit more useful). You can then include that in the templates used to create a personal space, and ask your users to use it correctly and not to remove it. Using <div> to do something along these lines is messy and inaccurate - divs are for layout of the body, and you'll be far better off investing in macros

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
Posted Jul 10, 2018 in Confluence

We want to see the templates you've created in Confluence!

Hi Community, Jessica here from the Confluence Product Marketing team!  July’s community challenge is all about sharing pictures  — and as an extension of our first post on what ...

698 views 21 12
Join discussion

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