CMSRepeater, Related pages and Teaser Image

Lennard van Diggelen asked on September 7, 2016 13:00

Hi There,

I'm trying to get the MenuItemTeaserImage in a CMSRepeater but after some searching I can't manage to get it working. The GetImage function is not working because its 'does not exist in the current context'. What am I doing wrong here?

                            <cms:CMSRepeater ID="RelatedRepeater" runat="server" ClassNames="CMS.Document" Path="/%" RelationshipName="isrelatedto" RelationshipWithNodeGUID="11111111-1111-1111-1111-111111111111">
                            <ItemTemplate>
                                <div class="col-lg-4 col-sm-9 col-xs-9">
                                    <a href='<%# Eval("NodeAliasPath") %>' class="related__block">
                                        <div class="related__imagewrapper">
                                            <img src='<%#  GetImage("MenuItemTeaserImage") %>' alt='<%# EvalText("DocumentName") %>' class="related__image">
                                        </div>
                                        <h4 class="related__title"><%# EvalText("DocumentName") %></h4>
                                        <span class="button button--secondary button--arrowright">Take a look</span>
                                    </a>
                                </div>
                            </ItemTemplate>
                        </cms:CMSRepeater>

Correct Answer

Jan Hermann answered on September 7, 2016 14:00

The GetImage method return whole img tag so it would break your HTML markup. What you need is the GetFileUrl method instead (taking also attachmentGUID as its parameter), but since the MenuItemTeaserImage already contains the attachmentGUID, you can build the url "manually" to save some performance:

<img src='/getattachment/<%# Eval("MenuItemTeaserImage") %>/<%# Eval("DocumentName") %>.aspx' alt='<%# EvalText("DocumentName") %>' class="related__image">

0 votesVote for this answer Unmark Correct answer

Recent Answers


Kristian Bortnik answered on September 7, 2016 13:16 (last edited on September 7, 2016 13:17)

The GetImage method is located in the CMSAbstractTransformation.Methods class (under the CMS.Controls namespace).

So you could do:

<%# CMSAbstractTransformation.Methods.GetImage(Eval("NodeAliasPath"), Eval("MenuItemTeaserImage")) %>

Or you could specify a transformation by setting the TransformationName on the Repeater control, instead of defining an <ItemTemplate> - that will give you access to transformation methods, as well as the ability to edit transformations in Kentico.

0 votesVote for this answer Mark as a Correct answer

Lennard van Diggelen answered on September 7, 2016 18:13

Hi guys,

Thank you for your replies. However, both of the methods aren't working. I get the error in both situations:

System.Web.HttpException: DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'MenuItemTeaserImage'.

0 votesVote for this answer Mark as a Correct answer

Lennard van Diggelen answered on September 7, 2016 21:50

Ok so I tried to add it with a transformation but it doesnt show up. It's an empty field. Even the GetImage does show the img tag but not the image as an url though I have certainly added it.

Am I doing something wrong here? Is there a specific approach on getting the teaser image in a transformation?

0 votesVote for this answer Mark as a Correct answer

Lennard van Diggelen answered on September 7, 2016 22:06

Now I use <%# GetFileUrl(Eval("MenuItemTeaserImage")) %> and get this in return.

/getattachment/00000000-0000-0000-0000-000000000000/Specialists

However this is still no valid image url. I know I'm close but there is something I just cannot figure out to get it to work. I'm certainly overlooking something.

Hope to hear from you!

0 votesVote for this answer Mark as a Correct answer

Lennard van Diggelen answered on September 8, 2016 08:52

I was missing the class CMS.MenuItem... I feel so stupid. Thanks for the advice!

0 votesVote for this answer Mark as a Correct answer

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