When Front End Meets Back End

Whilst working on the next iteration of Expanse (Expanse 5) - the CMS I built to power all of mine and my clients web sites I came across a particular scenario in which I initially wanted to solve essentially with front end code.

Expanse has its own template language, a set of moustache tags that directly relate to database fields and some additions to help with functional strings and loops. So if I wanted a link to a full article all I’d need to type in the templates would be {permalink} - this tag is generated from the stored url and directory title of the page.
Expanse also has custom fields, and in particular in Expanse 5 these custom fields are more powerful than ever. Having taken a look at the usage of these fields, we decided to make the input text rich. We applied our WYSIWYG editor Redactor II to the field and went to test. However there are some curveball instances where having a rich field isn’t appropriate for design. Custom Fields can be added anywhere to the page, so it makes sense to be able to appropriately allow semantically that same level of flexibility.

At first we looked at allowing for a pipe operator to be passed to the template code that would allow for our back end code to pick up the operator and apply the appropriate PHP function to the string. For example, if we wanted to remove HTML tags from the Field value of the custom field we initially wanted to be able to write {field|strip_tags}. This didn’t play well with our already in existence template class though. And after a while we took a step back. Is this really what we want to do? Does adding more variables to our template generation a realistic option when we already provide a way for PHP to interact directly inside the templates?

In the end we scrapped the whole idea of piping and resolved ourselves to make use of the PHP tag inside the Expanse Template System. To strip the tags we’d simply need to write {php}strip_tags({field}){/php}.

When PHP is so readily available to us in this way, we have to remind ourselves why try to make things overly simple when writing templates in the front end, when in turn making the back end overly complicated, especially when back end technologies are already achievable in the front end.

Posted On: Friday, January 6th, 2017 @ 1:37 pm by Ian Tearle


There are no comments on this entry. You should add one below.

Leave a comment

Be kind

If you would like to discuss anything about this post, please be polite and add your comments below.



No HTML is allowed. All links, and new lines will be automagically converted to HTML for you.
Notice to spammers, all links will be sanitized with rel="nofollow".

Contact Me

Get In Touch

If you would like to discuss anything about your next project please drop me a line.



Projects start at £99.00 per month
We normally book 2–3 months in advance.


No matter how small your project is, or if the prices above scare you, please do get in touch, I shall always listen and will advise freely alternative ideas or solutions. If you are a charity, let's talk!

Find Me On