This project is read-only.

Customization - Hyperlink to Dictionary of Terms

Sep 10, 2011 at 4:06 PM

Hi All!

I have a blog for sailor. In this blog I created a new page that inherits BlogBasePage. This page contains a Dictionary of Sailing Terms.

I want to modify the code in Visual Studio so that in all my Posts (not Pages) anytime one of the Sailing Terms exists, the Post will automatically generate a link to page containing the Dictionary of Sailing Terms going to the appropriate letter.

In post.aspx.cs, I'm thinking of adding the bolded line below under the OnInit event. Then create an XML file that contains the Sailing terms and the InsertSailingTermsLink function will automatically search post.Content string for Sailing Terms and insert the link.

Suggestions, Anyone?


            Post post = Post.GetPost(id);
            post.Content = InsertSailingTermsLink(post.Content); //gerardo 9/10/2011

Sep 10, 2011 at 4:55 PM
Edited Sep 10, 2011 at 4:56 PM

Use extension with settings - with code below you can do all you described and maintain dictionary of terms using extension/edit page cleanly. Just save it as SailingTerms.cs in ~/app_code/extensions folder.


using System.Data;
using BlogEngine.Core;
using BlogEngine.Core.Web.Controls;
using BlogEngine.Core.Web.Extensions;

[Extension("Sailing Terms", "", "the author")]
public class SailingTerms
    static ExtensionSettings terms;
    public SailingTerms()
        Post.Serving += PostServing;

    private void PostServing(object sender, ServingEventArgs e)
        var table = Terms.GetDataTable();
        const string s = "<a href=\"{0}\">{1}</a>";
        if (table != null && table.Rows.Count > 0)
            foreach (DataRow row in table.Rows)
                e.Body = e.Body.Replace(row["Term"].ToString(), string.Format(s, row["Url"], row["Term"]));

    public static ExtensionSettings Terms
            if (terms == null)
                var extensionSettings = new ExtensionSettings();
                extensionSettings.AddValues(new[] { "anchor", "" });
                terms = ExtensionManager.InitSettings("SailingTerms", extensionSettings);
            return terms;
            terms = value;
Sep 11, 2011 at 2:10 PM

Hi rtur!

The Extension solution worked very well!

Thank you.