Cleaner custom templates - best practices/ideas when outputting html using php

Permalink
Hi There,

As a designer who trains other designers to use c5, I've found the mixing of php and html in c5 custom templates (and more recently, in core_commerce) hard to follow.

Questions:
1. Are there any templating engines available for c5?
2. Or is there a way to better separate php logic from HTML?
3. Or are there formatting rules a designer could follow that would help simplify things?

After doing a bit of research, some developers feel that php is already a templating language so why have another one like smarty - which seems like a fair call.

But some c5 custom templates aren't that clean (to us designers) - as an example, here's Expression Engine's page_list equivalent (with pagination):
{exp:channel:entries channel="news" orderby="date" sort="desc" limit="1" paginate="bottom"}
  <h2>{title}</h2>
  {summary}
  {body}
  {paginate}
    <p>Page {current_page} of {total_pages} pages {pagination_links}</p>
  {/paginate}
{/exp:channel:entries}


Or in Modx:
[!Ditto? &parents=`5` &extenders=`summary` &tpl=`template_name` &orderBy=`createdon ASC` &display=`6` &truncText=`Continue Reading This Article` &dateFormat=`%e %B %Y`!]
// And the template:
<h1>[+pagetitle+]</h1>
<p>[+summary+]</p>
<p>[+link+]</p>


Obviously a lot of time has gone into the tags for EE & Modx so I'm not expecting to be able to make things as clean as the examples above.

We're also using Jordan's clean block templates which have helped clean up some of the more common templates but block templates for add-ons and core commerce don't seem to be developed to the same formatting standards.

Any pointers, ideas or tips on how to simplify/better organise templates would be much appreciated.

Cheers

Ben

View Replies:
bobrocke replied on at Permalink Reply
bobrocke
There hasn't been any activity on this post, so I'm assuming not many in the concrete5 development community see the need for a tempting language beyond PHP.

You would have to learn "another" language, but that's not a problem for most developers I know who are already using HTML, PHP, JavaScript, SQL, Python and maybe even a bit of Perl.

I'm new to concrete5 and love it's integrated CMS abilities, but working in the Blade template language from Laravel 4 (blade.php) is very nice. The SilverStripe template language (.ss) is not too bad, either.

I didn't notice the loss when I worked in Kirby (it uses straight PHP for templating, too), but once I tried another framework, I saw the value in cleaner, easier to follow and maintain, HTML files.

Would there be a way to tie in something like Twig? I don't have much experience with it, but it is available on Packagist.
JohntheFish replied on at Permalink Reply
JohntheFish
There are addons using templates for specific purposes. For example, Email special Instructions uses mustache.

My own Magic Data can (amongst other things) be used to turn any block into a template that is filled using Magic Data tokens.
bobrocke replied on at Permalink Reply
bobrocke
There hasn't been any activity on this post, so I'm assuming not many in the concrete5 development community see the need for a tempting language beyond PHP.

You would have to learn "another" language, but that's not a problem for most developers I know who are already using HTML, PHP, JavaScript, SQL, Python and maybe even a bit of Perl.

I'm new to concrete5 and love it's integrated CMS abilities, but working in the Blade template language from Laravel 4 (blade.php) is very nice. The SilverStripe template language (.ss) is not too bad, either.

I didn't notice the loss when I worked in Kirby (it uses straight PHP for templating, too), but once I tried another framework, I saw the value in cleaner, easier to follow and maintain, HTML files.

Would there be a way to tie in something like Twig? I don't have much experience with it, but it is available on Packagist.
TheRealSean replied on at Permalink Reply
TheRealSean
I would be interested in applying something like this too, having spent some time in Symfony2 and twig I can see the benefit of an extra language instead of a pure php approach.

With 5.7 maybe something like this could be considered??
cmscss replied on at Permalink Reply
Original poster here,

In the end, we used the principles outlined here:http://getkirby.com/blog/php-templates... which gives us more readable front-end templates like this:
<? if (is_array($visitors)) : ?>
  <? foreach ($visitors as $k => $vis) : ?>
  <li>
    <a href="<?= BASE_URL.$c->getCollectionPath()?>?category=<?= $th->urlify($vis) ?>">
      <?= $vis; ?>
    </a>
  </li>
  <? endforeach; ?>
<? endif; ?>

But we still find that in general, the front-end coding standards in c5 seem to take more of a developer's approach (as opposed to a designer's approach) to front-end output if that makes sense?

Cheers

Ben