Copied to clipboard

Flag this post as spam?

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


  • pbl_dk 149 posts 550 karma points
    Apr 06, 2015 @ 13:07
    pbl_dk
    0

    Max length of text field for summary

    Hello forum.

    I am trying to make a summary for the frontpage. I have an article text field on the page nodes below the frontpage. Any tips to how I can make an output which limits text for ie. 200 chars ("summary snippet") for the frontpage in razor?

     

    thanks :-)

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Apr 06, 2015 @ 13:21
    Jan Skovgaard
    2

    Hi Elitenet and welcome to our :)

    I think you should consider using pure CSS for achieving this rather than using a truncate technique for instance since the text is then just cropped at an unnatural place sometimes and it can be really hard to control.

    So I urge you to use the text-overflow: ellipis technique instead, which you can read more about here https://css-tricks.com/almanac/properties/t/text-overflow/

    This has the benefit that the text is not cropped but will be written in the HTML source so it's still accessible and makes sense if a search engine bot is visiting the site or if a person is using a screenreader.

    By using a truncate approach the text will be cropped of and make no sense. With the approach linked to above it's only the visual context of the text that is changed.

    I hope this makes sense.

    /Jan

  • Alex 79 posts 416 karma points
    Aug 12, 2015 @ 10:37
    Alex
    1

    hi

    pls tell me what limit of word of text string document type in umbraco admin side

    thanks

  • pbl_dk 149 posts 550 karma points
    Apr 06, 2015 @ 15:12
    pbl_dk
    0

    Hi Jan

    thanks for the reply and creative workaround, thats an option I could easily implement and would make sense.
    I am just thinking, would it be possible to break the text in the text field with some kind of marker in the code? have you ever seen something like that used in Umbraco?
    Im thinking of the same feature as in wordpress' "read more" tag.

    Thanks! :-)
    /Peter
     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Apr 06, 2015 @ 15:18
    Jan Skovgaard
    0

    Hi Peter

    The way I see it's this is the proper solution, not the workaround. Truncating the string is a workaround, which has some bad side-effects in my humble opinion :)

    You can set dimensions some dimensions on your elements where these texts should be displayed where you can add the readmore link after the "cropped" text.

    But if you want to use a workaround then you can use Substring for instance...

    Like this @Model.Content.GetPropertyValue("yourproperty").ToString().Substring(0, 200)

    /Jan

  • pbl_dk 149 posts 550 karma points
    Apr 06, 2015 @ 15:26
    pbl_dk
    0

    Yes it has a bad effect cause the text will be abnormally "cut". 
    I will try to experiment with some kind of indexOf command in razor, now that I see your code, that might be possible to cut the text with a character known to the editor.
    Thank you for the help!

    :-) /Peter 

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Apr 06, 2015 @ 15:31
    Jan Skovgaard
    0

    Hi Peter

    You're welcome - Looking forward to see what solution you come up with :) Ah yes indeed indexof should also be possible to use.

    /Jan

  • Proxicode 127 posts 323 karma points
    Apr 07, 2015 @ 01:43
    Proxicode
    1

    I like to use Tim Geyssens Prop editor for this. I usually use it for page meta info and limit to the recommended lengths. 53 chars for Title, 155 chars for Meta Description etc. I think it would be perfect for your use here. http://www.nibble.be/?p=285

    It works great & shows remaining characters as the user is typing. Simple to set up too.

    I do agree with Jan that substring is a bad idea - especially if it's a rich text editor, pretty good chance you'd end up chopping a html tag.

    Thanks -Roger

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Apr 07, 2015 @ 08:49
    Jan Skovgaard
    0

    Yeah the char limit package is good for limiting a field in the backoffice and making sure it's never becoming longer than X number of characters. It's good for SEO fields. But sometimes a summary for an article for instance will be longer and when one visits the article page the summary should be shown in full length but when viewing the article overview page you might want to limit the display of the summary...and then the char limit package does not make sense :) - So it's a matter of the context I'd say.

    /Jan

  • pbl_dk 149 posts 550 karma points
    May 26, 2015 @ 11:50
    pbl_dk
    0

    Hi Jan I finally put this together, also found some useful stuff on forum. Just some cleanup, not very clean code though. Optionally, if this should work like a SEO module, I would need a couple of keywords, and the "truncate-code" should search for a sentence which included the keyword, and it would take excerpt from that. But that will be a later version. (I think Yoast works almost like that).

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    @{
        var _textItem = @CurrentPage.summary.ToString();
        _textItem = _textItem.Replace("<p>", "");
        _textItem = _textItem.Replace("</p>", "");
        _textItem = _textItem.Replace("<br />", " ");
        _textItem = _textItem.Replace("<br/>", " ");
        _textItem = _textItem.Replace("</strong>", "");
        _textItem = _textItem.Replace("<strong>", "");
        _textItem = _textItem.Replace("\"", "");
    }
    @if (_textItem.Length < 150)
    {
        @_textItem
    }
    else
    {
        @_textItem.Substring(0, 150)
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft