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.
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.
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?
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.
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
is working on a reply...