Jump to content


Photo

Newbie Question on template tags

template

  • Please log in to reply
5 replies to this topic

#1 totoff

totoff

    Distinguished Member

  • Members
  • PipPipPipPip
  • 108 posts
  • 68

  • LocationCologne, Germany

Posted 10 August 2012 - 10:10 AM

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

#2 apeisa

apeisa

    Hero Member

  • Moderators
  • 2,586 posts
  • 905

  • LocationVihti, Finland

Posted 10 August 2012 - 10:28 AM

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.

#3 SiNNuT

SiNNuT

    Sr. Member

  • Members
  • PipPipPipPip
  • 378 posts
  • 236

Posted 10 August 2012 - 10:29 AM

Those curly braces aren't some kind of tags but 'normal' PHP complex string parsing.
http://www.php.net/m...parsing.complex

#4 totoff

totoff

    Distinguished Member

  • Members
  • PipPipPipPip
  • 108 posts
  • 68

  • LocationCologne, Germany

Posted 10 August 2012 - 10:30 AM

Hope this helps

It does. Thank you very much, both.

#5 Martijn Geerts

Martijn Geerts

    Sr. Member

  • Members
  • PipPipPipPip
  • 379 posts
  • 173

Posted 10 August 2012 - 10:33 AM

Think you have a typo, your code is not valid HTML or PHP.


{$child->url}

This is valid, but be aware of the right quotes.

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

to be save use <?php echo instead of <?= ( php shorthand )

#6 apeisa

apeisa

    Hero Member

  • Moderators
  • 2,586 posts
  • 905

  • LocationVihti, Finland

Posted 10 August 2012 - 10:46 AM

<?= 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, 10 August 2012 - 10:55 AM.
<?= will be always enabled, <? follows the short_tags setting on php.ini in 5.4+






Also tagged with one or more of these keywords: template

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users