[RFC] Template system: alternative syntax for DEFINE

These requests for comments/change have lead to an implemented feature that has been successfully merged into the 3.1/Ascraeus branch. Everything listed in this forum will be available in phpBB 3.1.
User avatar
Arty
Former Team Member
Posts: 985
Joined: Wed Mar 06, 2002 2:36 pm
Location: Mars
Contact:

[RFC] Template system: alternative syntax for DEFINE

Post by Arty »

Currently DEFINE has the following syntax: <!-- DEFINE $VAR = 'value' --> that works great for setting simple variables.

Problem is, it doesn't work for complex variables. It is not possible to join several string or use another template variable as value. I suggest to extend DEFINE syntax a bit to make it more powerful:

Code: Select all

<!-- DEFINE $VAR -->
value
<!-- ENDDEFINE -->
With such syntax you can:

Use variables as value: <!-- DEFINE $POST_AUTHOR -->{postrow.POST_AUTHOR}<-- ENDDEFINE -->
Use shorter conditional statements: The following code

Code: Select all

<!-- IF whatever --><!-- DEFINE $VAR = '1' --><!-- ELSE --><!-- DEFINE $VAR = '2' --><!-- ENDIF -->
can be written as

Code: Select all

<!-- DEFINE $VAR --><!-- IF whatever -->1<!-- ELSE -->2<!-- ENDIF --><!-- ENDDEFINE -->
that's a bit shorter. Real difference can be noticed on complex conditional statements with several ELSEIF.

But the biggest advantage is it allows inserting content in other templates, similar to TWIG's blocks. For example, if in overall_header.html you have this code:

Code: Select all

<html>
<head>
    header stuff here
    {$HEADER_META}
</head>
<body>
   stuff here
  menu start
  menu end
    {$MENU_AFTER}
you can add stuff to header from another template before including overall_header.html:

Code: Select all

<!-- DEFINE $HEADER_META -->{$HEADER_META}
<link rel="whatever" href="whatever" />
<!-- ENDDEFINE -->
<!-- INCLUDE overall_header.html -->
the rest of template
It also would allow moving whole blocks of content outside of loops:

Code: Select all

<!-- BEGIN postrow -->
   post stuff
   <!-- IF postrow.SOMETHING -->
     <!-- DEFINE $IMPORTANT_DATA -->
        some important information inside current post that you want to display after all posts, using {postrow.WHATEVER} variables available only in this loop!
     <!-- ENDDEFINE -->
   <!-- ENDIF -->
  more post stuff
<!-- END postrow -->
{$IMPORTANT_DATA}
It could be used to avoid duplicating code:

Code: Select all

<!-- BEGIN postrow -->
<!-- DEFINE $POST_AUTHOR_LINK --><!-- IF postrow.U_POST_AUTHOR --><a href="{U_POST_AUTHOR}"<!-- ELSE --><span<!-- ENDIF --><!-- IF postrow.POSTER_COLOR --> style="color: {postrow.POSTER_COLOR}"<!-- ENDIF -->>{postrow.POSTER_NAME}<!-- IF postrow.U_POST_AUTHOR --></a><!-- ELSE --></span><!-- ENDIF --><!-- ENDDEFINE -->

<div class="postprofile">
 <p class="post-author">{$POST_AUTHOR_LINK}</p>
</div>
<div class="post">
  <p class="post-time">Posted by {$POST_AUTHOR_LINK} at {postrow.TIME}</p>
</div>
<!-- END postrow -->

User avatar
MichaelC
Development Team
Development Team
Posts: 889
Joined: Thu Jan 28, 2010 6:29 pm

Re: Template system: alternative syntax for DEFINE

Post by MichaelC »

+1
Formerly known as Unknown Bliss
psoTFX wrote: I went with Olympus because as I said to the teams ... "It's been one hell of a hill to climb"
No unsolicited PMs please except for quotes.

keith10456
Registered User
Posts: 523
Joined: Sat Apr 22, 2006 10:29 pm
Contact:

Re: Template system: alternative syntax for DEFINE

Post by keith10456 »

+1

Good idea, and good explanation of the idea ;)

User avatar
Vinny
Style Customisations
Style Customisations
Posts: 129
Joined: Thu May 20, 2010 4:01 am
Location: Brazil
Contact:

Re: Template system: alternative syntax for DEFINE

Post by Vinny »

+1

VOLKERMORD
Registered User
Posts: 7
Joined: Sat Mar 09, 2013 2:36 pm

Re: Template system: alternative syntax for DEFINE

Post by VOLKERMORD »

+1

User avatar
Marc
Development Team Leader
Development Team Leader
Posts: 185
Joined: Thu Sep 09, 2010 11:36 am
Location: Munich, Germany

Re: Template system: alternative syntax for DEFINE

Post by Marc »

One thing that actually works is defining a template variable with another variable.
This will work:

Code: Select all

<!-- DEFINE $VAR = '{foobar.VAR}' -->
Same goes for this:

Code: Select all

<!-- DEFINE $VAR = '{FOOBAR}' -->
I generally like your idea though.

+1


User avatar
callumacrae
Former Team Member
Posts: 1046
Joined: Tue Apr 27, 2010 9:37 am
Location: England
Contact:

Re: Template system: alternative syntax for DEFINE

Post by callumacrae »

Marc wrote:One thing that actually works is defining a template variable with another variable.
This will work:

Code: Select all

<!-- DEFINE $VAR = '{foobar.VAR}' -->
Same goes for this:

Code: Select all

<!-- DEFINE $VAR = '{FOOBAR}' -->
I generally like your idea though.

+1
I'd prefer this, but it may be trickier to parse:

Code: Select all

<!-- DEFINE $VAR = foobar.VAR -->
Made by developers, for developers!
My blog

User avatar
sitesplat
Registered User
Posts: 8
Joined: Wed Dec 10, 2014 4:28 pm

Re: Template system: alternative syntax for DEFINE

Post by sitesplat »

+1 for the OP idea.
Slightly off topic. Would this be considered for 3.0.x? Maybe open a ticket? :-)
Last edited by sitesplat on Wed Dec 10, 2014 9:10 pm, edited 1 time in total.
- FLATBOOTS - phpBB Flat Design - Bootstrap3
- Contact me Via PM or e-mail for Custom work
- Deploy an SSD cloud server in 55 seconds. Sign up and get $10 in credit.

User avatar
DavidIQ
Customisations Team Leader
Customisations Team Leader
Posts: 1903
Joined: Thu Mar 02, 2006 4:29 pm
Location: Earth
Contact:

Re: Template system: alternative syntax for DEFINE

Post by DavidIQ »

No. 3.0.x will be getting a few maintenance/bug fix releases and then EOL'd a little after that. No solid dates have been set for that though.
Image

Post Reply