@Frenzie : yes ... twig, smarty and most of the other template engines are complex and just another syntax for PHP code at all. I wouldn't use any of them...
But that's not the case with Mustache.. the logic (some special cases) would have to be moved to the controller.
Another example, taken from ElkArte code:
// Is the clock ticking?
if (!empty($context['poll']['expire_time']))
echo '
<p>
<strong>', ($context['poll']['is_expired'] ? $txt['poll_expired_on'] : $txt['poll_expires_on']), ':</strong> ', $context['poll']['expire_time'], '
</p>';
in mustache.php you could do it that way:
{{#context.poll.is_expired}}
<p>
<strong>{{txt.poll.expires_on}}:</strong> {{context.poll.expire_time}}
</p>
{{/context.poll.is_expired}}
another approach would be
// poll expired? let's show a small warning
if ($context['poll']['is_expired'])
echo $mustache->render($render_data, 'poll_expired');
and
<p>
<strong>{{txt.poll.expires_on}}:</strong> {{context.poll.expire_time}}
</p>
I think both versions are easier to read compared to the original ElkArte code..
If you look at the more complex templates, espacially those with mixed HTML, PHP and Javscript:
if (!empty($context['attachments']['ila_enabled']))
{
addInlineJavascript('
var IlaDropEvents = {
UploadSuccess: function($button, data) {
var inlineAttach = ElkInlineAttachments(\'#postAttachment2,#postAttachment\', \'' . $context['post_box_name'] . '\', {
trigger: $(\'<div class="share icon i-share" />\')
});
inlineAttach.addInterface($button, data.attachid);
},
RemoveSuccess: function(attachid) {
var inlineAttach = ElkInlineAttachments(\'#postAttachment2,#postAttachment\', \'' . $context['post_box_name'] . '\', {
trigger: $(\'<div class="share icon i-share" />\')
});
inlineAttach.removeAttach(attachid);
}
};', true);
}
IMHO that code is readable for a skilled developer but not for an average designer, typical problems here:
where do I use single quotes / double quotes?
where do I need to escape a quote with a backslash?
Another possible case:
Let's assume our controller would just give you JSON data. You could render that code on the server side (with mustache.php) and also on the client side, for example inside an android or IOS app (JS version of mustache) by using the exact same templates.