Pragmatism in the real world

Additional Content Blocks

I hacked together support for additional content blocks in CMS Made Simple over the last few days. This constitutes the first time I’ve hacked the main code and I’m pretty damn proud of myself!

In the end the feature wasn’t as difficult to write as it might have been. This is due to some rather clever design in the back end. First off, the database already separated out storage of the main text and header tags for each content page into a separate table. Thus it was easy enough to add in a variable number of extra text fields into the database. The admin interface is written using separate content classes, derived form ContentBase. So I modified the Edit() function of the the content class to add in the new textareas and away I went :)

The only tricky bit was getting the data back out of the database and into the form. The problem here is that the secondary data table (content_props) is loaded before the Content class gets to find out the template id and hence work out if there are any additional content blocks or not. I solved this by reloading the properties in Edit(), but it doesn’t seem quite as clean as it could be.

To do the front end side, I introduced a new function, ContentPreRender(), into ContentBase. This works in a similar fashion to the function of the same name in ModuleBase and allows the content class to access the raw template, process it and return it back to the display function.

Nice and easy all in all!