Search code examples
kentico

Kentico Trim in a transformation with Eval


I'm trying to trim ending white space from AlertTitle in an ascx transforamtion. I know there is TrimEnd, but i'm drawing a blank getting it to work.

The V9 Documentation has a method for this(https://docs.kentico.com/display/K9/Adding+custom+methods+to+transformations) but i don't want to fix the length.

Here's the transformatin code snippet.

<asp:placeholder id="alert" runat="server" Visible="false">  
  <li data-date="<%# Eval("AlertDate") %>">
    <p class="alert-date"><%# FormatDateTime(Eval("AlertDate"), "MMMM dd, yyyy") %> </p>
    <p class="alert-copy"><%# Eval("AlertTitle") %>  <%# IfEmpty(Eval("AlertCopy"),"", "... <a href='" +  GetDocumentUrl() + "'>" + CMS.Helpers.ResHelper.GetString("kff.Generic-ReadMore") + "</a> &raquo")  %></p>
  </li>
</asp:placeholder>


Solution

  • In addition to using Trim() or TrimEnd() in the transformation, you can also set it up so Kentico will automatically trim the fields when the form is submitted by checking the "Trim" checkbox under "advanced" Editing control settings.

    Like so:

    Trim field