This project is read-only.

Extensions on Pages and Posts

Topics: Controls
Jan 30, 2011 at 12:21 PM

Trying to get different extensions that are meant to be used in Posts to work in Pages. Really geting confused anyone with some advice?

Jan 30, 2011 at 5:01 PM

Take a look at existing extensions, for example MediaElementPlayer works in both posts and pages. You basically have to register both events pointing to your custom handler function:

Post.Serving += Publishable_Serving;
BlogEngine.Core.Page.Serving += Publishable_Serving;

Then in your function do whatever you extension supposed to do:

private static void Publishable_Serving(object sender, ServingEventArgs e)
	// list locations you want extension to handle
	if (e.Location == ServingLocation.PostList || e.Location == ServingLocation.SinglePost || e.Location == ServingLocation.Feed || e.Location == ServingLocation.SinglePage) {

		// e.Body is a content of you post or page
		// your custom code here

		// page specific code if needed
		HttpContext context = HttpContext.Current;
		if (context.CurrentHandler is Page) {
			Page page = (Page)context.CurrentHandler;
			// custom code here

Jan 31, 2011 at 2:03 PM

Thanks, appreciate the help having great fun looking good so far.

Feb 1, 2011 at 9:13 PM

This also works for the syntax highlighter included in BE 2.0 - Thanks! All I had to do was edit the SyntaxHighlighter.cs file in the App_Code/extensions folder as shown below.

    static SyntaxHighlighter()
        Post.Serving += AddSyntaxHighlighter;

       //Added this line
        BlogEngine.Core.Page.Serving += AddSyntaxHighlighter;