The Problem

MODX is a great CMS and generally what I turn to when I have any sort of web related project. With all the power it provides, there have been many times when I get caught up in trying to make modifications in the wrong way.

A perfect example is converting my site to using Markdown when writing my blog posts. Sure, there are other CMS's and blogging engines that have it built-in. You can also find easily installable plugins to make it work. But I wanted to use MODX, and while there was a plugin available, it requires you to place your code between tags that would then be replaced. While not a bad solution, that extra step just didn't appeal to me.

So anyhow, here I am with my fancy MODX install, my blog all configured using Articles to handle posts, and I decided that I really needed Markdown support. I mean, how fantastic would it be to write all my blog posts in plain text from any editor I wanted and just copy/paste it right in when it was ready.

The Investigation

My journey to add the support started with me digging into Articles and modifying Articles.class.php to do my bidding. This was great until an update was release, and of course after updating I needed to re-apply my updates. My next thought was to add a plugin. I already had a plugin parsing my documents and rendering code blocks, adding Markdown should be a piece of cake. So off I go creating a plugin and things were good, until I found a problem (turns out the problem was in my original solution as well.)

The problem I found, was when I wanted to show a summary of my post, it wasn't being rendered correctly. More specifically, either the Markdown was not being parsed at all, or tags were not being closed properly causing issues with the page as a whole. At this point, I had already spent more time than I planned and didn't really have any ideas on how to fix the problem without some convoluted way of going about it. So I deactivated my plugin, re-applied my changes to Articles, and went along my merry way (this was the least problematic solution for me at the time.)

The Solution

Fast-forward to today, and I see there is an update for Articles and I would like to update to this latest version of it. So I upgrade, and then remembered that I needed to re-apply my fixes. And then it hit me... an output filter would be awesome for this. So I created a snippet, updated my template to call the output filter and all was fixed. To top it off, I could now also call the same filter to be applied to post summaries and it didn't have any of the problems I had experienced before. BTW, I also realized the ellipsis output filter actually closes HTML tags, which is kind of awesome.

And just incase anyone was curious, I call my new filter like this:

For post summaries:

[[+introtext:default=`[[+content:markdown:ellipsis=`400`]]`]]

And the actual blog template:

 [[*content:markdown]]

Comments

comments powered by Disqus