Flat-file CMS for front-end developers
<TextField>
A flat-file CMS for front-end developers. Write your HTML, mark a few variables as editable, and <TextField> gives your client a dashboard for the rest. No database, no admin theme to learn.
<article>
<h2>{article_title}</h2>
{article_text}
</article>
<TextField> is different.
No database, no setup wizard. <TextField> stores everything in plain JSON files next to your theme, so installing it means copying a folder and nothing else.
You keep full control of the markup. Build your theme however you want, then mark a handful of variables as editable. Your client gets a dashboard for text, images and content blocks, without ever touching your code.
The documentation right below is short. Ten minutes of reading and you'll know how <TextField> works.
Installation
Unzip the archive and copy all of its contents (the core/, panel/, themes/, uploads/ and vendors/ folders and the .php files) to your project root, and that's it: <TextField> is installed.
<TextField> stores its data in .json files and needs no database. It runs on PHP 8.4.
Open ./panel/ on your web server. The first time, you create the administrator account yourself: username, email and password (8 characters minimum). There's no default password to remember or change later.
To create your theme, add a folder in themes/ with at least an index.html template, then pick it in Settings › System › Theme: the site switches theme as soon as you save.
Build the data tree
The data is divided into 2 types of elements:
- Static contents, which are single fields. Example: the description of the website.
- Flows, which are sets of items. Example: a portfolio. Items of a flow share the same fields.
It's a good idea to create a .json file for each independent part of your website to avoid useless loads. Example: the portfolio and the about text are stored in home.json, and the blog in blog.json.
Files, fields and flows are created from the panel while developer mode is on (Settings › System).
Load your theme
Each public page is a PHP file at the root. Open index.php: load(DATAS.'home') loads the core/data/home.json data file, and tpl::parse(THEMES.'index') renders the index.html template of the active theme. Paths are written without the extension. Change these names to match yours, and duplicate the load() line to load more than one data file.
To create a separate page, copy index.php in the same folder, rename it, then change the files passed to load() and tpl::parse(). Links between pages call these root .php files.
In your templates, build the paths to the theme's assets with {base_url} (the site address) and {theme} (the active theme folder, e.g. themes/mytheme/):
<link rel="stylesheet" href="{base_url}/{theme}css/main.css">
{include $theme.'header'}
This way your paths keep working whatever the theme folder is called, even with rewritten addresses such as /blog/article/3.
Inject the data
In the panel, the matching variable name is shown under each field and each flow. Call a variable to display its value: {about_text}. This form outputs the value as is, HTML included, which is what you want for a markdown or editor field. For plain text, an HTML attribute or any value typed by a visitor, use {=about_text}, which escapes HTML.
Use the following syntax for flows:
{item in $articles} <!-- "item" is a prefix to avoid conflicts, name it as you want -->
<h2>{=item_title}</h2>
{item_text}
{end}
To set a condition, use this syntax:
{if /*PHP syntax here, you have access to all the variables*/}
<!-- content -->
{elseif /*PHP syntax*/}
<!-- content -->
{else}
<!-- content -->
{end}
A few more tags:
{include $theme.'header'}inserts another template, such as a shared header or footer;{"Read more"}outputs a text translated by the theme's language file (see "Multilingual site");{?echo date('d/m/Y');}runs raw PHP;{!outputs an opening brace without parsing it, handy in an inline script or stylesheet.
<TextField> runs on the Templite engine, which has its own documentation (short too) further down this page.
Extra contents
In a loop, each item automatically gets a number, {item_id} (the prefix followed by _id): its zero-based position in the flow. In sortFlow() and filterFlow(), the same number is called id, i.e. $item['id'].
Some field types create extra variables, named after the field:
- date and time:
{date_formatted}, using the format set in Settings › System, and the parts{date_Y},{date_m},{date_d},{date_j},{date_F},{date_M}(plus_H,_iand_swhen a time is entered); - image: the value becomes the
uploads/…path, with{photo_width},{photo_height},{photo_alt}and, when a thumbnail exists,{photo_thumb}; - file: the value becomes the
uploads/…path; - tags: a list to loop over,
{t in $item_tags}{t_name}{end}. The flow also gets the list of all its tags with their item count:{t in $blog_tags}{t_name} ({t_items}){end}.
Every page also gets {base_url}, {theme}, {year}, {site_lang} and {site_languages}.
To see all the available variables and their content, turn on Settings › System › Theme › "Variables list": the list is added as a comment at the very end of each page's source, for users logged into the panel only. You can also uncomment the #tpl::fix(); line of a root PHP file, but then every visitor can see the list.
Sort and filter flow items
{prefix in sortFlow($flow, 'id')}...{end} sorts a flow by ascending id.
{prefix in sortFlow($flow, 'date', true)}...{end} sorts a flow by descending date.
{prefix in filterFlow($flow, fn($item) => $item['id'] <= 3)}...{end} selects the items whose id is 3 or less.
{prefix in sortFlow(filterFlow($flow, fn($item) => $item['id'] <= 3), 'id', true)}...{end} filters, then sorts the matching items.
{prefix in filterFlowByTag($flow, 'php')}...{end} keeps the items tagged "php".
Dates are compared chronologically. The filterFlow() condition is written in PHP: $item holds the item's fields. filterFlowByTag() reads the tags field (pass another name as the third parameter) and ignores case.
Multilingual site
Declare the site languages in Settings › System › Languages: the first one is the default language. The "Use the visitor's preferred browser language" option picks a new visitor's language automatically.
Translated texts live in a variant of the data file, home.en.json next to home.json. It only holds the entries that change: everything else (images, dates, settings) comes from the default file. The panel creates this variant for you by copying the page.
Texts written in templates as {"Read more"} are translated in themes/<theme>/lang/<code>.lang, one line per text: "Read more" = "Lire la suite".
For a language switcher, and for the <html lang="{site_lang}"> attribute:
{l in $site_languages}<a href="{l_url}"{if $l_active} aria-current="true"{end}>{l_label}</a>{end}Publish
Before going live, in Settings › System:
- Turn off developer mode to freeze the data tree: the panel then refuses to create, rename or delete files, fields and flows.
- Turn off "Variables list" and check that no
tpl::fix();line is uncommented in your root PHP files. - Turn the cache on and set its duration (0 everywhere: each copy is kept until the cache is cleared).
The cache only serves anonymous visitors, with one copy per address and per language. Every save in the panel clears it, so your changes show up right away. The "Publish" button also clears the compiled templates, and the thumbnails when the matching option is on.
Templite
Templite is the PHP template engine behind this CMS. It weighs about 5 KB.
It keeps the data handling out of your HTML without making you learn a new language. Tags compile down to plain PHP, so there's very little standing between your template and the page it produces.
Variables, nested loops, conditions, includes, translations, a page cache: it covers what you'd expect from a template engine, and it stays fast while doing it.
Readable syntax
Tags are short and sit naturally in the HTML around them, so a template is still easy to read a month later.
Nested blocks
Nest loops as deep as you need. Each loop gets its own prefix, so the variables of two levels never collide.
Conditions
Variables are available directly in the template, so a condition is just a PHP expression wrapped in an if tag.
PHP functions
Templates accept native PHP: pass a variable through any function before printing it.
Translations
Put the fixed texts of your site in a language file and Templite swaps them in. A text with no translation is printed as written.
Includes
A template can include another one. Each included file is compiled on its own and reused on the next call.
Speed
Templite loads in about 0.1 ms, compiles a large template in under 5 ms and renders it in around 10 ms, with no cache at all.
Page cache
Anonymous visitors get a cached copy of each page, one per address (query string included) and per language. You choose how long a copy lives in the panel, and any save clears them.
Readable output
The compiled code is plain PHP you can open, which helps when a tag doesn't do what you expected. Templite never rewrites your paths: build them with {base_url} and {theme} and they work whatever the theme folder is called.
Debug
Turn on the variables list in the panel and each page ends with a comment listing every variable and block it received. Only users logged into the panel see it.
Automatic recompile
Edit a template or a language file and Templite recompiles it on the next request. Nothing to clear by hand.
Light as a feather
All of the above fits in about 5 KB of PHP once the comments are stripped.
Buy <TextField> CMS
See License Agreement for full terms and conditions. For inquiries about licensing, billing and secure payment processing, please, use support@textfield.org.
One time-payment, not a subscription.
Pro
€199 Inc. VAT
You are a team/developer and you create websites for your clients or you have a hosted web service with the subscription or Intranet site.
- Unlimited websites for your own clients & projects
- Unlimited developers, domains & sub-domains
- Full access to source code
- Free updates for current major version
- 50% discount for the next major version
- Technical support by email
- Not included: redistributing <TextField> as part of a product you sell — see OEM
OEM
€999 Inc. VAT
You sell or distribute software like Design template. And you deliver <TextField> along with your product code.
- Redistribution rights: bundle & ship <TextField> inside a product (theme, starter kit, platform) you sell or distribute
- Unlimited end-customers receiving your product
- Unlimited developers, domains & sub-domains
- Full access to source code
- Free updates for current major version
- 50% discount for the next major version
- Technical support by email
Secure payment by Stripe
- Visa
- Mastercard
- American Express
We never see or store your card details. One-time payment, receipt sent by email.
Already a customer? Download your copy