Example #1

ExpressionEngine (from this article)

{embed=layout/header}
   <h1>{exp:channel:category_heading channel="reviews"}{category_name}{/exp:channel:category_heading}</h1>
   {exp:channel:entries channel="reviews"}
      <article class="review">
         <h2><a href="{url_title_path=reviews}">Reviews in {title}</a></h2>
         <p class="meta">Posted on {entry_date format="%Y %m %d"}</p>
         <p>{content}</p>
      </article>
   {/exp:channel:entries}
{/embed=layout/footer}

ProcessWire

include("header"); 
   e("<h1>{$page->category->title}</h1>");
   foreach($pages->find("parent=/reviews/") as $review) e("
      <article class='review'>
         <h2><a href='{$review->url}'>Reviews in {$review->title}</a></h2>
         <p class='meta'>Posted on {$review->date}</p>
         <p>{$review->content}</p>
      <article>");
include("footer"); 

Note: In ProcessWire the output date format is set with the fieldtype in the Admin CP.

ProcessWire (same thing as above, but using alternate syntax going in and out of PHP… some people prefer this, though I prefer the above)

<? include("./header.inc"); ?>
   <h1><?=$page->category->title?></h1>
   <? foreach($pages->get("/reviews/")->children() as $review: ?>
   <article>
      <h2><a href="<?=$review->url?>">Reviews in <?=$review->title?></a></h2>
      <p class="meta">Posted on <?=$review->date?></p>
      <p><?=$review->content?></p>
   </article>
   <? endforeach; ?>
<? include("./footer.inc"); ?>

Example #2

ExpressionEngine

{exp:channel:entries channel='faq'}
    {if count == 1}
        <ul>
    {/if}
    <li><a href="{title_permalink=faq/entry}">{title}</a></li>
    {if count == absolute_results}
        </ul>
    {/if}
    {if no_results}
        <h1>No entries found</h1>
    {/if}
{/exp:channel:entries}

ProcessWire

$li = '';
foreach($pages->find("parent=/faq/") as $e)
    $li .= "<li><a href='{$e->url}'>{$e->title}</a></li>";
echo $li ? "<ul>$li</ul>" : "<h1>No entries found</h1>";

Dictator CMS and ProcessWire v1 used tag-based syntax, why v2 doesn't use tag based syntax and why you may be better off without a template engine.

More about ProcessWire syntax here and here.

Comments

  • lossendae

    lossendae 7 years ago 00

    How about a template engine who stay close to php enough, like Razor (example: http://code.google.com/p/yii-razor-view-render/wiki/GettingStarted)

  • Ryan Cramer

    Ryan Cramer 7 years ago 00

    Razor looks interesting, I will take a closer look. Thanks.

  • Alan Bristow

    Alan Bristow 7 years ago 00

    Ryan, I love the cleanliness of your example code (I hope this comment does not strip the code I am pasting ;)

    include("header");

    e("{$page->category->title}");

    I've not come across "e(" and then typing HTML and then inserting PHP with just the "{", very clean.

    Only one worry I had (for a mortal like me who will likely make some mistakes if the know-your-PHP-bar is set too high) was, is this "Warning It is very important..." http://goo.gl/78aUf applicable to this type of formatting?

  • Rey

    Rey 6 years ago 00

    What does e( and .= means?

    *Super noobie here, sorry for the dumb question :(*

  • diogo

    diogo 6 years ago 00

    @rey, I never came across a e() function neither, but it can be achieved like this:

    function e($myString)

    {

    echo $myString;

    }

  • diogo

    diogo 6 years ago 00

    for .= see here http://php.net/manual/en/language.operators.string.php

  • Yannick Albert

    Yannick Albert 3 years ago 00

    e() ist just a shortcut to the htmlspecialchars() function, I think...

  • Yannick Albert

    Yannick Albert 3 years ago 00

    for e( see here http://platesphp.com/templates/escaping/

Post a Comment

Your e-mail is kept confidential and not included with your comment. Website is optional.