Copied to clipboard

Flag this post as spam?

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


  • Stewart Ellis 25 posts 64 karma points
    Apr 28, 2011 @ 23:45
    Stewart Ellis
    0

    using HtmlAgilityPack in page template

    I have a requirement to strip out some content from a bodyText field, based on whether or not a person is a logged in member. Specifically, I need to strip out a column from an html table if the person is not logged in. From what I've ready, the HtmlAgilityPack seems like the right candidate, but I'm not sure how to wire it up in a MasterPage template.

    I started with this...

         <%  HtmlAgilityPack.HtmlDocument doc new HtmlAgilityPack.HtmlDocument(); %>
         <%  doc.Load( %><umbraco:Item field="bodyText" runat="server"></umbraco:Item><)); %>

    ... but quickly realized that would not fly.

    I can't figure out how to pass the bodyText content into the HtmlAgilityPack, in my MasterPage. 

    Can anybody shed some light on this?

     

     

     

     

     

     

  • Lennart Stoop 304 posts 842 karma points
    Apr 29, 2011 @ 00:34
    Lennart Stoop
    0

    Hi Stewart,

    My inline template coding skills aren't great, but you should also be able to access the property via the node factory like this:

      <%  
        HtmlAgilityPack.HtmlDocument doc new HtmlAgilityPack.HtmlDocument(); 
        doc.LoadHtml(umbraco.presentation.nodeFactory.Node.GetCurrent().GetProperty("bodyText").Value);
        Response.Write(doc.DocumentNode.WriteTo());
      %>

    I would recommend creating a macro for this though, and pass the property in as a parameter.

    Depending on the version of Umbraco you are using you could then create a razor script or a .NET user control which contains the stripping logic.

  • Stewart Ellis 25 posts 64 karma points
    May 06, 2011 @ 04:01
    Stewart Ellis
    0

    Hi Lennart, the nice little umbraco auto-reminder-to-close-a-post-thingy just sent me a prompt regarding this post, and indeed your insights solved my issue.

    Thanks very much

     

    Stewart

     

Please Sign in or register to post replies

Write your reply to:

Draft