How can I embed the content of a text file attachment into a wiki page?

I have a process that automatically attaches a file to a wiki page, and now I want to embed that text file into the page contents itself. Is there an equivalent to the {include} macro for text file attachments?

6 answers

I see the following options:

  1. You can write your own plugin
  2. You can write your own user macro and use it to display iframe with the attached file contents (not sure if that will work - just an idea)
  3. You could change your process to create/update Confluence page instead of attaching file and use excerpt macro whenever you need to include it on a different page.

swiniak,

Thanks for the response, but it really wasn't very helpful. Yes, there are lots of thing that I could do myself, but I was looking for someone that has already solved this problem.

Well... you did not state you wanted a working solution. I just gave some tips on how can you do it (which could be helpfull if you're not too familiar with Confluence)... so now you'll just need to wait for another response or you can start working on it yourself :)

I too would like to see something list the "View File Macro" for text files (http://confluence.atlassian.com/display/DOC/View+File+Macro).

For example:

{viewdoc:name=my document.doc}
{viewppt:name=my presentation.ppt}
{viewxls:name=my spreadsheet.xls}
{viewpdf:name=my document.pdf}

But I would like to be able to do this with a text file like this:

{viewtxt:name=myfile.txt}

I have lots of text file scripts that I want to display in confluence pages, but I don't want to have to edit, copy, and paste every single script. I just want to upload them as attachments to one page and then reference them in other pages. Much easier to upload a text file script after I have changed it than having to edit every single page and do the edit, copy, paste steps.

--- @ James Hines

Would this work around work for you? I know it is a stretch, and I'm not sure if this would produce the results you would want to see, but could you put your content in one cell of an Excel Speadsheet and then use this macro to display the content?

{viewxls:name=Book1.xls|sheet=Sheet1|row=0|col=0}

Good luck...

James, rather than attaching to a page, why dont you put the contents itself directly into the page, using the Confluence CLI?

@Renjith, what is confluence CLI?

A similar question has been asked before, and an answer provided at the old forum (http://forums.atlassian.com/thread.jspa?threadID=43212) The solution involves generating a path using some Velocity objects to reference a particular attachment. The browser takes care of accessing the content of the file and rendering it. All of this Functionality is wrapped up in a user macro, so you can re-use it on multiple pages.

Link is broken :(

atlassian forums is gone now

Thanks everyone for your suggestions. Charles solution was the closest to what I am wanting to do. I created a user macro as suggested in the forum thread, and the solution is working in Google Chrome. On IE and Firefox it is more problemmatic. Seems like they each handle the <embed> tag slightly differently.

If you're only going to be accessing text files then you don't need to restrict yourself to the <embed> tag. An alternative is to use jQuery (client side code) to retrieve the contents of the attachment and insert it into another element, such as a div.

Here's an example to help you: http://stackoverflow.com/questions/6470567/jquery-load-txt-file-and-insert-into-div

You wouldn't need the button-click trigger, just make the ajax call within the (document).ready() block.

I would expect this to overcome any browser specific issues.

I'd be interested in your finished solution if you could post it back here, as would others I expect. :)

Cheers,

Charles

Hi,  its just about 2015 - does anyone know of a solution for this use case?

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Kesha Thillainayagam
Posted Apr 13, 2018 in Confluence

We want to hear how your non-technical teams are using Confluence!

Hi Community! Kesha (kay-sha) from the Confluence marketing team here! Can you share stories with us on how your non-technical (think Marketing, Sales, HR, legal, etc.) teams are using Confluen...

388 views 21 10
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