Simple Website Framework

Helper Functions

Monday April 20th, 2026

Written by Scary le Poo

The framework exposes several utility functions that are available globally in theme files, layout files, shortcode functions, and anywhere else PHP runs within the request lifecycle.


Markdown Functions

These are defined in required/initialize-markdown-parser.php, which wraps the bundled PHP Markdown Parser library (required/PHP-Markdown-Parser/).

from_markdown($string)

Converts a Markdown string to HTML and returns the result.

$html = from_markdown("# Hello\n\nThis is **bold**.");
// Returns: <h1>Hello</h1><p>This is <strong>bold</strong>.</p>

This is used by all page-md layout files to render page content, by navigation.php to render the navigation list, and by footercolumns.php to render footer content. You can call it anywhere you want to render Markdown.


to_markdown($string)

Converts an HTML string back to Markdown. The inverse of from_markdown().

$markdown = to_markdown("<h1>Hello</h1><p>World</p>");

This is less commonly needed but available if you need to convert HTML content for storage or export purposes.


Date Functions

Defined in required/helperfunctions.php.

formatDate($inputDate, $outputDateFormat)

Parses a date string in any of several supported formats and returns it formatted as specified. Returns false if the input cannot be parsed.

Supported input formats: - Y-m-d H:i:s (e.g. 2024-06-15 00:00:00) - l F jS, Y (e.g. Saturday June 15th, 2024) - m/d/Y (e.g. 06/15/2024)

Supported output format values:

Value Output example
'Y-m-d H:i:s' 2024-06-15 00:00:00
'pretty' Saturday June 15th, 2024

Example:

echo formatDate("06/15/2024", 'pretty');
// Outputs: Saturday June 15th, 2024

echo formatDate("2024-06-15 00:00:00", 'pretty');
// Outputs: Saturday June 15th, 2024

The framework calls formatDate() in header.php to normalise $pagedate before writing it to the OpenGraph og:article:published_time meta tag, and in page-md.php to display the formatted date under the title for article page types.


Metadata Extraction

Defined in required/vitalfunctions.php.

extractValueFromPattern($pagename, $pattern)

Reads the file pages/[pagename].html and applies a regex pattern to extract a value from an HTML comment metadata block. Returns the trimmed match, or null if not found.

$title = extractValueFromPattern("about", '/<!--\s+pagetitle:(.*?)\s+-->/s');

You generally won't need to call this directly — vitalfunctions.php calls it automatically for all standard metadata fields and stores the results in $pagetitle, $pagelayout, $pagedate, etc. It's documented here in case you want to define custom metadata fields in your page files and extract them in a theme or shortcode.

Adding a custom metadata field:

Add your comment to a page file:

<!-- mycustomfield: Some value -->

Extract it in your theme or shortcode:

$myvalue = extractValueFromPattern($pagename, '/<!--\s+mycustomfield:(.*?)\s+-->/s');
Simple Website Framework

A lean, flat-file PHP framework with no database, no bloat, and no black boxes. Build something clean and keep control of every part of it.

Contribute on GitHub

Found a bug? Have an idea? The project is open source and contributions are welcome. Find it on GitHub.

Documentation

This site is the living documentation for the framework. Every feature is demonstrated in the place it's meant to be used. Start with the introduction or dive straight into the setup guide.