Thursday, 19 September 2013

PHP User Based Templating

PHP User Based Templating

Hi I'm creating a system where users can create their own themes, styles,
and templates. I'm storing their page templates in a mysql db and
currently I've written a small replace script that uses tags so the user
can define where content should go in their template elements. The script
replaces their tags with their content during when the page is rendered.
What I want to do now is add the ability for them to define a section
conditionally - so for example they might have an element in their
template that looks like this:
<h1 class="entry-title">
<span class="top-left-ribbon"></span>
@titlebar>heading
<span class="sub-heading">@titlebar>subheading</span>
<span class="right-ribbon"></span>
</h1>
Replacing the titlebar heading and subheading with the required values is
no problem, but I can't figure out how to do the following and replace the
conditionals with php if statements and have it process.
<h1 class="entry-title">
<span class="top-left-ribbon"></span>
@titlebar>heading
@titlebar?subheading
<span class="sub-heading" >@titlebar>subheading</span>
<span class="right-ribbon"></span>
@end?
</h1>
Basically I would want to replace
@titlebar?subheading
@end?
With...
if($titlebar->subheading){ }
And process through php appropriately.
Any suggestions would be appreciates.

No comments:

Post a Comment