kentico

How can I format text to Title Case from within a transformation in Kentico?


Within a transformation in Kentico, I am trying to format text to title case. I have discovered CMS.Helpers.TextHelper.ToTitleCase() in some Kentico documentation but, I don't believe that is available from within a transformation. I was also hoping I could get access to a TextInfo.ToTitleCase() via one of the CultureInfo objects in Kentico (like CMS.Localization.LocalizationContext.CurrentCulture.TextInfo.ToTitleCase()) but that doesn't seem to be available within the transformation either.

Any advice would really be appreciated. [This is in a Kentico 11 website]


Solution

  • This depends on what type of transformation you are using. If you're using an ASCX transformation type, you can use the following:

    CMS.Helpers.TextHelper.ToTitleCase(Eval<string>("ColumnName"))
    

    If you're using a Text/HTML transformation type you would have to create a custom macro method to call that TextHelper method and return the title case value you're expecting.