Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • pubudu 30 posts 133 karma points
    Apr 26, 2019 @ 09:22
    pubudu
    0

    Umbraco.Truncate

    Have another way to use this in Umbraco8? I got this line in Umbraco7 tutorial.

    " @Umbraco.Truncate(news.newsBodyText, 100) "

    I want to only show 200 words in my article on Parent page. enter image description here

  • Rhys Hamilton 140 posts 942 karma points
    Apr 26, 2019 @ 09:47
    Rhys Hamilton
    1

    Umbraco.Truncate() is now Html.Truncate() in V8, so try using that instead.

  • pubudu 30 posts 133 karma points
    Apr 26, 2019 @ 10:09
    pubudu
    1

    Thanks Rhys! how to write other code? (news.newsBodyText, 100) is not working

  • Rhys Hamilton 140 posts 942 karma points
    Apr 26, 2019 @ 11:42
    Rhys Hamilton
    0

    You'll need to either supply the appropriate Model or use .Value().

    So, you could try something like:

    foreach (News news in NewsList)
    

    Where News is the name of your Model - this might be different for you.

    In which case, your .Truncate() method would look like:

    @Html.Truncate(news.NewsBodyText, 100)
    

    To put it all together, your code could look something like:

    @foreach (News news in NewsList)
    {
        <div class="inner" style="width:100% !important">
            <div class="content">
                <header>
                    <h3><a href="@news.Url">@news.Name</a></h3>
                </header>
                <div class="image fit">
                    <img src="images/pic01.jpg" alt="" />
                </div>
                <p>
                    @Html.Truncate(news.NewsBodyText, 100) 
                </p>
            </div>
        </div>
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft