Correct way to write 'replace' macro and will it work in email template

steve burleigh asked on October 20, 2017 18:18

Hi there

I'm trying to check whether or not a macro i've got is written correctly but cannot find any specific examples.

Scenario

I'm using a bizform to capture user inputs, one of which is an image upload. Using the autoresponder email, i want to return parts of this data input to the user. The email will be formatted (hopefully) to display the user's data in a specific way.

I've been able to use macros to capture all inputs - but I'm having problems with capturing the url of the image uploaded. Whilst i can resolve the value {%UploadControl%} - teh actual value won't work as an image path.

I know i need to add /CMSModules/BizForms/CMSPages/GetBizFormFile.aspx?filename= in front of the macro - but this still leaves the problem of the filename being appended to the end of the url i.e. /CMSModules/BizForms/CMSPages/GetBizFormFile.aspx?filename=7bb05492-0f0c-438d-93dd-5f84a748de2f.jpg/ice-council-banner-tablet.jpg

A colleague has suggested using the replace method to remove the '/' from the url and replace it with an '&' He's given me this macro {% Replace(UploadControl, ‘/’, ‘&’)%} - unfortunately this is not resolving.

Can anyone confirm if a) that's the correct syntax and b) whether or not this macro would ever work in an email template?

If not, is there a way either within the CMS or through custom development to get the path of a document uploaded to a bizform?

Thanks

Steve

Correct Answer

Rui Wang answered on October 20, 2017 19:46

The HTML for that is the following, make sure to switch to source view to enter the HTML

{% imgURL = Substring(UploadControl, 0, IndexOf(UploadControl, &quot;/&quot;)); return; %} <img src="/Kentico10/CMSPages/GetBizFormFile.aspx?filename={% imgURL %} " /><br />

0 votesVote for this answer Unmark Correct answer

Recent Answers


Rui Wang answered on October 20, 2017 19:14 (last edited on October 20, 2017 19:31)

First, are you trying this in the Auto Responder feature of the Form?

Are you trying to display a link to the attachment, which you can get by just select the UploadFile field and insert the value (e.g. $$value:UploadControl$$). The URL I got is something like this /CMSPages/GetBizFormFile.aspx?filename=71177384-ba70-4901-80fe-4161a7dab5e1.jpg&sitename=DancingGoat (for V10), not sure why your format needs the "/CMSModules/BizForms" part.

Or are you trying to convert into something like <img src="/..../{% URL %}" /> so the image displays in the email?

If the second option, you can use {% Substring(UploadControl, 0, IndexOf(UploadControl, "/")) %} so it will trim 7bb05492-0f0c-438d-93dd-5f84a748de2f.jpg/ice-council-banner-tablet.jpg to 7bb05492-0f0c-438d-93dd-5f84a748de2f.jpg, then just add /CMSPages/GetBizFormFile.aspx?filename= in front of that

0 votesVote for this answer Mark as a Correct answer

steve burleigh answered on October 21, 2017 11:34

Hi Rui

Many thanks for that - worked a treat!

Steve

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.