Jump to content

Newbie Question on template tags


totoff
 Share

Recommended Posts

hello forum,

i've read somewhere in the docs that the use of template tags was given up with the switch from version 1 to 2.

does that mean this code

<li><a$class href='{$child->url}'>{$child->title}</a></li>

as found in the head.inc with the official download is no longer valid? Or is the use of curly brackets a regular use of PHP (I'm very new to PHP unfortunately)?

Wouldn't you rather write

<?php echo $child->url ?>

instead of

{$child->url}

??

thanks, christoph

  • Like 1
Link to comment
Share on other sites

Everything you find from processwire.com is valid. Version 1 was closed source system and Ryan only references it on his "background articles".

Curly brackets work only inside php tags already. Your first example should be:

<?php
echo "<li><a$class href='{$child->url}'>{$child->title}</a></li>";
?>

If you are writing pure html then simplest way to output variables is:

<li><a <?= $class ?>href='<?= $child->url ?>'><?= $child->title ?></a></li>

Curly brackets are necessary when going deeper than one level on your objects, like this:

<li><a <?= $class ?>href='<?= {$child->related_page->url} ?>'><?= {$child->related_page->title} ?></a></li>

Hope this helps. PW uses pure PHP as a templating language.

  • Like 1
Link to comment
Share on other sites

<?= and <? will be always enabled from PHP 5.4+ so if you don't need to support some rare shared hosts where shorthands are disabled then those are perfectly safe to use.

Edited by apeisa
<?= will be always enabled, <? follows the short_tags setting on php.ini in 5.4+
  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...