Copied to clipboard

Flag this post as spam?

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


  • vijayadurga 17 posts 37 karma points
    Jun 01, 2013 @ 14:50
    vijayadurga
    0

    Remove <p> tags in Umbraco 6

    Hi

    can any one help me on this

     

    i have inserted Umbraco filed but it contains Html content with empty <p> tags

    My Umbraco field .. How can Add removeparagraphtags for this field

    @Umbraco.Field("pageTitle")

     

    Thanks

     

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jun 01, 2013 @ 17:10
    Dennis Aaen
    0

    Hi vijayadurga,

    You could do it several ways, If you want to out the value in the a template you could do it like this:

    <umbraco:Item field="pageTitle" stripParagraph="true" runat="server" />

    If you will do it XSLT you can do it like this

    <xsl:value-of select="$currentPage/pageTile" disable-output-escaping=yes />

    In Razor you should could do it like this:

    @(Html.Raw(Model.PageTitle)).

    I hope this can help you.

    /Dennis

     

  • David Prothero 23 posts 106 karma points
    Aug 15, 2013 @ 00:42
    David Prothero
    0

    The Razor syntax you show doesn't seem to help. The Umbraco rich text editor seems to put the paragraph tag in the field for you.

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Aug 15, 2013 @ 08:04
    Dennis Aaen
    0

    Oh my bad,

    Have you tried use the library method StripHtml.

    @Library.StripHtml()

    /Dennis

  • David Prothero 23 posts 106 karma points
    Aug 15, 2013 @ 17:16
    David Prothero
    0

    Yeah, that would strip out ALL html. Not sure if the OP intended this, but I just wanted to strip out the <p></p> the rich text editor seems to insist putting around any content. Was hoping there was a way to disable that behavior. In lieu of that, I just wrote a simple utility function:

     

    public IHtmlString StripOuterParagraph(string content)
    {
        string newContent = content;
    
        if (newContent.ToLower().StartsWith("<p>")) {
            newContent = newContent.Substring(3);
        }
    
        if (newContent.ToLower().EndsWith("</p>")) {
            newContent = newContent.Substring(0, newContent.Length - 4);
        }
    
        return new HtmlString(newContent);
    }
  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Aug 15, 2013 @ 17:58
    Dennis Aaen
    0

    Hi David,

    You show be able to strip to strip specific tags also.

    If you only wanted to strip specific tags, such as <p> tags, that should be able by doing this line of code:

    @Library.StripHtml(Model.fieldAlias, "p")

    /Dennis

  • Colin Watson 17 posts 47 karma points
    Aug 13, 2014 @ 12:21
    Colin Watson
    0

    Thanks Dennis, stripParagraph="true" works like a treat

     

    Colin

Please Sign in or register to post replies

Write your reply to:

Draft