Okay, I don't want a complete answer to this problem. But we are trying to convert our XSLT files to Razor and I am having a difficult time accessing some images from a Media Picker type and displaying them.
We are trying to display 3 images on a single page each with different alias (i.e. ad1image, ad2image, ad3image). Here is the XSLT that works for this setup. I would love some explanation as to what the variable "class" and "mediaId" are doing and what would be a method to try to convert this file to Razor.
Both class and mediaid are macro parameters passed in from the Template. The "class" appears to simply be the class name to apply to the <img> tag. The "mediaid" is likely from a MediaPicker which translates the media selected to an id.
takes the mediaid and gets the XML data for the media item (image). Inside that media XML is a node called "umbracoFile" which contains the file path to the image.
Also, there is a "style" parameter that is passed in with adds a style attribute to the <img> tag if present.
Thanks for helping me understand the Parameter aspect of macros. This was extremely helpful. With your help and some other forum posts, I was able to get our code working.
The final code for the project ended up being:
@{ var media = new umbraco.cms.businesslogic.media.Media(Convert.ToInt32(@Parameter.mediaId)); string imageUrl = media.getProperty("umbracoFile").Value.ToString(); <img src="@imageUrl" />
}
Images displayed just fine and I now have a better understanding of parameters and (hopefully) more about the Media Picker.
Converting Media Picker XSLT to Razor
Okay, I don't want a complete answer to this problem. But we are trying to convert our XSLT files to Razor and I am having a difficult time accessing some images from a Media Picker type and displaying them.
We are trying to display 3 images on a single page each with different alias (i.e. ad1image, ad2image, ad3image). Here is the XSLT that works for this setup. I would love some explanation as to what the variable "class" and "mediaId" are doing and what would be a method to try to convert this file to Razor.
Thanks in advance.
Both class and mediaid are macro parameters passed in from the Template. The "class" appears to simply be the class name to apply to the <img> tag. The "mediaid" is likely from a MediaPicker which translates the media selected to an id.
This line:
takes the mediaid and gets the XML data for the media item (image). Inside that media XML is a node called "umbracoFile" which contains the file path to the image.
Also, there is a "style" parameter that is passed in with adds a style attribute to the <img> tag if present.
Does that help?
Jason,
Thanks for helping me understand the Parameter aspect of macros. This was extremely helpful. With your help and some other forum posts, I was able to get our code working.
The final code for the project ended up being:
Images displayed just fine and I now have a better understanding of parameters and (hopefully) more about the Media Picker.
Excellent! Glad I could help, and thanks for posting your final code. That will help others in your situation in the future!
-Jason
is working on a reply...