var content = contentEventArgs.Content as StandardPage;
Then check if it's not null and you should find your XhtmlString properties. StandardPage could of course be a base class or interface or whatever type you need to modify. You could also cast to PageData and iterate the property collection.
Thanks Johan. I did what you suggested in both the PublishedContent and SavingContent events. Here is an example:
private void OnPublishedContent(object sender, ContentEventArgs contentEventArgs) { var content = contentEventArgs.Content as PageData; if (content != null)
Inspecting that content object, I still can't locate the markup. Performing a print content in the Visual Studio command window returns this output.
ID = 102_361, Name = "Checking 1", Page Type = "InteriorPage" [Castle.Proxies.InteriorPageProxy]: ID = 102_361, Name = "Checking 1", Page Type = "InteriorPage" base {EPiServer.Core.ContentData}: ID = 102_361, Name = "Checking 1", Page Type = "InteriorPage" ACL: {{Inherited}} ArchiveLink: {} Category: {} Changed: {1/12/2017 9:37:48 AM} ChangedBy: "kepalmer" ContentAssetsID: {00000000-0000-0000-0000-000000000000} ContentGuid: {e98c7b59-a77c-41e9-994c-de72a9926766} ContentLink: {102_361} ContentTypeID: 9 Created: {1/12/2017 9:37:12 AM} CreatedBy: "kepalmer" Deleted: null DeletedBy: "" ExistingLanguages: Count = 1 ExternalURL: "" HasTemplate: true IsDeleted: false IsMasterLanguageBranch: true IsModified: false IsPendingPublish: false IsVisibleOnSite: true Language: {en} LanguageBranch: "en" LanguageID: "en" LinkType: Normal LinkURL: "/link/e98c7b59a77c41e9994cde72a9926766.aspx?epslanguage=en" MasterLanguage: {en} MasterLanguageBranch: "en" Name: "Checking 1" PageFolderID: 0 PageGuid: {e98c7b59-a77c-41e9-994c-de72a9926766} PageLanguages: {EPiServer.Core.ReadOnlyStringList} PageLink: {102_361} PageName: "Checking 1" PageTypeID: 9 PageTypeName: "InteriorPage" ParentLink: {42} PendingArchive: false PendingPublish: false Saved: {1/26/2017 10:52:56 AM} SetChangedOnPublish: false StartPublish: {1/12/2017 9:37:12 AM} StaticLinkURL: "/link/e98c7b59a77c41e9994cde72a9926766.aspx" Status: Published StopPublish: {12/31/9999 11:59:59 PM} URLSegment: "checking1" VisibleInMenu: true WorkPageID: 361 >
I also tried casting contentEventArgs as StandardPage, but was unable to locate the namespace for that. Consequently I ran with PageData.
Am I looking in the wrong place? Thanks for helping me out.
In this case it looks like you would need to "as InteriorPage" if you want to access the typed Html properties. If you cast to PageData you can instead do content["SomePropName"].
Thanks Johan, that worked. Here is what I did in case this helps someone else out.
private void OnPublishingContent(object sender, ContentEventArgs contentEventArgs) { adjustMarkup(ref contentEventArgs); } private void OnSavingContent(object sender, ContentEventArgs contentEventArgs) { adjustMarkup(ref contentEventArgs); } private void adjustMarkup(ref ContentEventArgs contentEventArgs) { InteriorPage content = contentEventArgs.Content as InteriorPage; if (content != null) { XhtmlString revisedContent = content.MainBody; // My helper class to customize the HTML. MakeCompliantMarkup returns an XhtmlString. WCAGHelper wcagHelper = new WCAGHelper(); content.MainBody = wcagHelper.MakeCompliantMarkup(revisedContent); wcagHelper = null; revisedContent = null; } }
Note, I shifted from using OnPublishedContent to OnPublishingContent since the MainBody property of contentEventArgs was read-only in the former. I really appreciate your help.
We are trying to alter some HTML when content is saved or published in EpiServer 8.0. In the Global.asax we registered an OnPublishedContent event and an OnSavingContent event. But upon inspecting the ContentEventArgs, I'm unable to locate the actual content markup that we want to adjust.
We have this in Application_Start()
And this is one of the signatures:
The "Content" property of ContentEventArgs shows ID, Name, and Page Type. But it doesn't show the markup. How do I get to that markup so we can adjust it before it gets saved? Thanks.