0

I am looking to Render a General Link Field in Sitecore 8.2 with Webforms. I also have the content inside the anchor <a> tag which needs to content editable in Experience Editor. Also, I want the <a> link to be editable in the Experience editor.

Example:

<% foreach (var discount in BindableModel.SearchResults)
            {%>
<div class="rc-card " data-location="<%= string.Join(",",discount.LocationsNames) %>">
            <%--Anchor tag to start here from sitecore General Link field--%>
            <div class="rc-card-media">
                <%= FieldRenderer.Render(discount.TargetItem, "ThumbnailImage") %>

                <% if (discount.Category != null && !string.IsNullOrEmpty(discount.Category.Color))
                    {
                %>
                <span class="disc-tag" style="background-color: <%= discount.Category.Color %>">
                    <%= FieldRenderer.Render(discount.Category.TargetItem, "Title") %>
                </span>
                <% } %>
            </div>
            <div class="rc-card-header">
                <div class="disc-card-title">
                    <h3><%= FieldRenderer.Render(discount.TargetItem, "Title") %></h3>
                </div>
            </div>
            <%-- Anchor tag to end here --%>
            <div class="rc-card-body">
                <div class="disc-card-desc"><%= FieldRenderer.Render(discount.TargetItem, "Summary") %></div>
                <div class="disc-card-offer-savings text-right">
                    <%= FieldRenderer.Render(discount.TargetItem, "TagLine") %>
                </div>
            </div>
            <div class="rc-card-footer">
                <% if (discount.RedemptionType != null)
                    {
                %>
                <div class="disc-redeem-icon">
                    <%= FieldRenderer.Render(discount.RedemptionType.TargetItem, "Icon") %>
                </div>
                <div class="disc-redeem-details">
                    <div>
                        <%= FieldRenderer.Render(discount.RedemptionType.TargetItem, "Intro") %>
                    </div>
                    <div>
                        <%= FieldRenderer.Render(discount.RedemptionType.TargetItem, "DetailsUrl") %>
                    </div>
                </div>
                <% } %>
            </div>
        </div>
<% } %>

I have added the comment in the above code where my anchor field start and ends. The anchor tag needs to be editable in the experience editor.

  • try <sc:Link Field="linkfieldname" runat="server" ID="link" Item="youritem"> <!--your content--> </sc:Link> – Mahendra Shekhawat Feb 14 at 4:27
  • @MahendraShekhawat would that still render the content inside if link field doesn't have a value? – Arun Kumar Feb 18 at 3:17
  • webforms are too old, I am not sure but if it doesn't you can handle this in your code by checking the null condition. – Mahendra Shekhawat Feb 18 at 7:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.