Accessing Image URL from templates
All,
We are currently using sitefinity 4.4 and looking to take advantage of the feature which allows developers to append “size=max width or height” to the end of a query string. Then the server would resize the image based up on the size parameter.
ex
URL http://domain.com/libraries/library_name/image_name.ext?size=640
Resizes to a maximum width or height of 640.
Our current problem is we want to add the size parameter to the query string within widget templates so we need access to the url of the following fields.
<img src="<%# Eval("PrimaryImageUrl") %>" />
<sf:AssetsField runat="server" DataFieldName="HeroImage" />
We were hoping for something like
<%# ( (ContentLink[]) Eval("ThumbnailImage") )[0].URL %>
Is this or anything similar possible?
Anthony, this should certainly be possible. The approach I use is to place a helper method in the code-behind of the template. This requires mapping an external widget template, but gives you more control over the rendering of the content properties.
What I usually do is do define a method like this:
protected
string
RenderImage(
object
contentItem)
var item = contentItem
as
MyContentItem;
<
img
src="<%# RenderImage(Container.DataItem) %>" />