Creating wiki-style links within the blog Almost works, except for a Get Post

Mar 6, 2013 at 8:07 PM
I wanted an easy way creat wiki-style links within my blog, so posts could easily lik to other posts or pages. I added a GetPostbyTitle method and created a wikilink extension.

It almost works.

private static void AddLink(object sender, ServingEventArgs e)

foreach (Match match in REGEX.Matches(e.Body))
       string wikiExpr = match.Groups[0].Value;
       string wikiTerm = match.Groups[1].Value.Trim();
       var wikiPost = Post.GetPostByTitle(wikiTerm);
       /// everything works perfectly is you put the string directly in, as below. 
      /// var wikiPost = Post.GetPostByTitle("Test Post");
       var link = string.Format("<a class=\"more\" href=\"{0}\">{1}</a>", wikiPost.RelativeLink, wikiTerm);

    e.Body = e.Body.Replace(match.Groups[0].Value, link);

Everyting works perfectly is I put the string directly into the GetPostByTitle. For some reaseon, though, when I use the wikiTerm var it fails "Object reference is not an instance of an object"