UMBRACO Razor - Write Out a Sub String and Write out a Substring Encoding



The Highlighted lines below shows you how to write out a Substring from Razor in Umbraco.

1) @Html.Raw(@item.HomePageIntro.ToString().Substring(0, 290))
or
2) @item.HomePageIntro.ToString().Substring(0, 290)

(Example 1 will write out the HTML characters, Example 2 removes Encoding.)

Example of writing out a SubString in Umbraco using Razor

@inherits umbraco.MacroEngines.DynamicNodeContext
@{ var numberOfItems = 6; }
    @foreach (var item in @Model.Children.Where("Visible").Take(numberOfItems))
    {<article>
        <figure><img src="images/triangle.jpg" alt=""></figure>
        <strong>@item.PageHeading </strong>
        <p>@Html.Raw(@item.HomePageIntro.ToString().Substring(0, 290))...</p>
<p class="more"><a href="@item.Url">FIND OUT MORE</a></p>
      </article>}

Comments

Popular posts from this blog

Umbraco Razor Sort Nodes Ascending or Descending

Umbraco Razor get Querystring

Create a .NET Contact Form that Gets the Last Url Visited in C# Can also be Used in Umbraco