Build a Flat-File CMS - Part 2


Data Files

data files

The data files contain site-specific data such as images, posts and pages.   The first ones that I will describe are 'posts' and 'content-blocks'.


Posts and Content Blocks reside in their own directories inside the data directory. and each has a unique name.   An example of a post file name:



Post and content block files contain character-string fields separated by delimiters.   I am using "***" as the delimiter for this example. 

Content block files contain a string of delimited fields that looks like this:

This is a Page About CATS ***    (title)

cute-cat-picture.jpg blah blah blah ***    (content -text, images, links, etc).


 Post files contain a string that looks like this:

11/11/2017 ***   (date)

This is a Post About CATS ***   (title)

cute-cat-picture.jpg    blah, blah, blah ***    (content)

cats###cat-food-recipes ***    (delimited string of categories)

draft ***   (status - 'draft', 'published' or 'trash')

cute-cat-featured-image.jpg ***   (featured image used for grids)

blog   (post group - either 'blog' or 'portfolio' currently)

PHP has an amazing pair of features - explode and implode, that convert strings to arrays and back again to strings which make it easy to manipulate these data files.

LilaWorks has  dedicated code modules for reading and writing to both post and content block files.  

If, in the future, more fields are needed with either file type, these two modules can be updated.

Category: coding,tutorials

Leave a Comment

Comments for Build a Flat-File CMS - Part 2