Insert Image in a template
Asked by Bill Ahern:

Is the Insert Image wiki markup able to utilize injection or other methods to insert an image in a live template. Here is the sample code.

{replace-and-render}  
{replace-item:%image%}{report-info:content:title\|source=@self}{replace-item}  
{replace-body}  
!staff:Staff Photos\^%image%.jpg!  
{replace-body}  
{replace-and-render}

This code currently generates this error message:

Unable to render content due to system error: com/atlassian/confluence/renderer/embedded/EmbeddedResourceUtils

I know this is a blend of 2 other macros, but the question goes to the format of the wiki markup for insert image.

Thanks.


Answers:
author: CharlesH
body: Hi Bill,

Glad its working for you now. Your version of my code is not the same though - when you're referring to a scaffold field you need to prefix the reference with "data:", so you need !staff:Staff Photos\^%data:imgfile%!

Regards,

Charles

comments: author: Bill Ahern
body: Hi Charles,

A slight oversite there ;)

I fixed and tried this

```
{report-on:injected=true}{set-data:imgfile|type=text}%page:title%.jpg{set-data}!staff:Staff Photos^%data:imgfile%!{report-on}
```

Still get the error. Oh well, will have to play some more to see if I can come up with a better method.

Thanks,

Bill


author: CharlesH
body: Hi Bill,

The good news: I've reproduced your situation exactly (on Conf 4.2.1) so I think this could be a bug. Feel free to log it with Atlassian.

The even better news: I have a workaround for you. This solution relies on the Report-on macro as before, but we use set-data from the Scaffolding plugin to record the page title into a variable. We can then retrieve this value successfully in the report-on block within the markup for the image.

Here's my test template, which I called as a live template with create-page. The first image reference doesn't work (same error message as you got) while the second one does.

```
Do you see the image?{report-on:injected=true}Image to grab: %page:title%.jpg{set-data:imgfile|type=text}%page:title%.jpg{set-data}!staff:Staff Photos^%page:title%.jpg! !staff:Staff Photos^%data:imgfile%! {report-on}
```

The difference is not massive. Perhaps it works correctly because the injection isn't follwed by ".jpg".

Regards,

Charles

comments: author: Bill Ahern
body: Hi Charles,

Thanks for the effort here! I tried your suggestion but still get the same error. I am running conf 4.2.2. I will file a but with Atlassian as you are able to repeat it.

Here is the code as you supplied:

```
{report-on:injected=true}{set-data:imgfile|type=text}%page:title%.jpg{set-data}!staff:Staff Photos^%imgfile%!{report-on}
```

As I said, no joy. I did get this to work though:

```
{replace-and-render}{replace-item:%image%}{report-info:content:title|source=@self}{replace-item}{replace-body}!http://MyURL/download/attachments/6160880/%image%.jpg!{replace-body}{replace-and-render}
```

I tried the URL in your suggestion, no good. It seems a bit of a hack to use the URL, but for now it works!

Thanks for your help!

Bill


author: CharlesH
body: I'd suggest trying the link-page macro, part of the Linking plugin offered by CustomWare. It's similar to create-page, available for free I think, and won't take long to set up. You may find the injection starts working with this macro. I've used both options, and with live templates, but I've not injected a value to make a reference to an image. Just one other thing - the template no longer contains any replace and render macros?

comments: author: Bill Ahern
body: I think you have clarified your responese with the statement "I've not injected a value to make a referenct to an image". That is what I am after, whether it is RnR or injection or whatever. The question is "Why does !staff:Staff Photos\^%page:title%.jpg! produce an error in a live template?


author: CharlesH
body: If you're using a live template, then the page only gets a title when you save it for the first time. After clicking the link to create the new page (based on the template) do you get taken to the page in Edit mode or View mode? If it's view mode I would expect the injection to work just fine. If it's Edit mode, then you'll have to save the page to see it work.

What macro are you using to offer the link to create the page? Also, what version of Confluence are you running?

comments: author: Bill Ahern
body: I am using the Adaptavist Create-page to actually create the page, but that is not really the issue as I am modifying an existing template. I think all of the injection stuff is actually working, the issue is using the !filepath\^filename.jpg! and when I just insert that into the template it generates the error shown above.

Is there another macro to embed an image?


author: CharlesH
body: I wonder if your approach is just a little over-complicated? I think it should be possible to achieve the result you're looking for with the aid of a report-on block alone. Set injection to true for this block, then all you need is to use the "insert wiki markup' option in the Insert menu of the rich text editor, and insert the following markup into that block: !staff:Staff Photos\^%page:title%!

comments: author: Bill Ahern
body: Thanks for the thought, usually simpler is better. I have tried this code:

{report-on:injected=true}

!staff:Staff Photos\^%page:title%.jpg!

{report-on}

and get: !staff:Staff Photos\^MyPageName.jpg! as a text line. At least I know the injection is working!

I did also try putting !staff:Staff Photos\^MyPageName.jpg! by itself and get this error:

Unable to render content due to system error: com/atlassian/confluence/renderer/embedded/EmbeddedResourceUtils

This is in a live template, when I tried your method in a static page it works. I just havent been able to locate any info on this error message.

Thanks.