Anyone here that can help me? I have the following code:
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
var node = @Model.NodeById(1257);
}
<div class="Top10">
<h1>Newest</h1>
@foreach (var article in node.Descendants().Where("Visible && (NodeTypeAlias = \"Article\" || NodeTypeAlias = \"sergrein\" || NodeTypeAlias = \"solomyndagrein\")").OrderBy("createDate desc").Take(10))
{
<a href="@article.Url"><h2>@article.createDate.ToString("dd/MM") | @article.title</h2></a>
}
</div>
What I want is: if @article.title is longer than e.g. 10 characters, it needs to return the 10 characters followed by ... (for example: "this_is_a_..."). If the @article.title is shorter than 10 characters, it can just show the full title length. How can this truncating be done?
Try this
@(article.title.Length > 10 ? (article.title.Substring(0,10) + " ...") : article.title)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With