Copied to clipboard

Flag this post as spam?

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


  • Darren Wilson 234 posts 622 karma points
    Nov 09, 2015 @ 11:35
    Darren Wilson
    0

    Adding links to truncated text

    Hi Folks,

    I have a partial view that's pulling in some truncated text. It's stripping out the links (between the tags) within the text. I've tries a couple of things on the forum to try and get it work, but these seem to produce an error. Is there a more efficient way to do this? Here's the code...

        @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @{ 
    var blogPosts = Umbraco.Content(1854); 
        foreach(var blogPost in blogPosts.Children().OrderBy("CreateDate desc").Take(1)){
            var mediaItem = Umbraco.TypedMedia(blogPost.linkToMedia);
            <div class="item-snippet-footer">
                  <li>
                        <h4>@blogPost.itemTitle</h4>
                        <p>@Umbraco.Truncate(blogPost.itemContent, 200, true)</p>
    
                        @if(mediaItem != null) {
                            <a href="@mediaItem.Url" target="_blank">Read More</a>
                        }
    
    
                  </li>
            </div>
        }
    }
    

    Thanks for your help with this! Darren

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Nov 09, 2015 @ 11:51
    Dirk De Grave
    0

    Have you tried to use @Umbraco.StripHtml() before using .Truncate()?

    See https://our.umbraco.org/documentation/Reference/Querying/UmbracoHelper/

    --Dirk

  • Darren Wilson 234 posts 622 karma points
    Nov 09, 2015 @ 11:58
    Darren Wilson
    0

    Hi Dirk,

    Thanks for the quick response!

    I actually want the full link to appear with the truncated text - LINK TEXT for example rather than as it appears just now.

    That's a great page you've recommended though - loads of good things on there!

    Darren

Please Sign in or register to post replies

Write your reply to:

Draft