Macro To Obtain Image Url from a Static HTML Webpart

Carlos Batista asked on November 26, 2015 20:21

This is a dumb question but I can't really find anything that has worked so far. So I have this pageType which contains certain amount of information and within the actual page I inserted a static html webpart that I want to style to look a certain way. Within the webpart im using certain macros to access the page's fields and everything is working perfectly, except my multiple attempts to get the Image Url of the attachment field in this page. {% TeaserImage %} returns a string that is not a usable URL. {% GetImage(TeaserImage) %} returns a full on image tag, which is just frustrating. I have tried a million other Macros but none of them returns a usable Image Url. I wonder if anyone knows the right method to call here to get the Url of this image.

Thanks in advance

Recent Answers


Roman Hutnyk answered on November 26, 2015 21:41

Carlos, what is type of TeaserImage fields? I can assume it is not URL. you should be able to check this in page type application, or in database. This could be either File or Attachment. Knowing what exactly it is will help you to determine appropriate macro.

0 votesVote for this answer Mark as a Correct answer

Carlos Batista answered on November 26, 2015 22:25 (last edited on November 26, 2015 22:28)

Thanks Roman, yes, it's a File data type input that only allows for jpg and png uploads. Im actually not sure if I should be using Attachments instead of a file input within the page type. I simply wanted to keep the page's information in a single place for the user to edit.

0 votesVote for this answer Mark as a Correct answer

Roman Hutnyk answered on November 26, 2015 23:09

So it saves GUID into TeaserImage column and actual image to the attachment table.

In this case I'd try something like this:

<img src="~/getattachment/{%TeaserImage%}" />

1 votesVote for this answer Mark as a Correct answer

Laura Frese answered on November 26, 2015 23:36

Or try "~/CMSPages/GetFile.aspx?guid={% TeaserImage %}" />

0 votesVote for this answer Mark as a Correct answer

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