[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
Registered User
Posts: 970
Joined: Wed Mar 06, 2002 2:36 pm
Location: Mars
Contact:

[RFC] Template system: alternative syntax for DEFINE

Post by Arty » Thu Mar 28, 2013 10:52 am

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 -->
Formerly known as CyberAlien.

Free phpBB styles | Premium responsive XenForo styles

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

Re: Template system: alternative syntax for DEFINE

Post by MichaelC » Thu Mar 28, 2013 1:51 pm

+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.

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

Re: Template system: alternative syntax for DEFINE

Post by keith10456 » Thu Mar 28, 2013 3:11 pm

+1

Good idea, and good explanation of the idea ;)


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

Re: Template system: alternative syntax for DEFINE

Post by VOLKERMORD » Sat Mar 30, 2013 3:43 am

+1

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

Re: Template system: alternative syntax for DEFINE

Post by Marc » Sat Mar 30, 2013 4:57 pm

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
Arty
Registered User
Posts: 970
Joined: Wed Mar 06, 2002 2:36 pm
Location: Mars
Contact:

Re: Template system: alternative syntax for DEFINE

Post by Arty » Tue Apr 09, 2013 8:35 am

Formerly known as CyberAlien.

Free phpBB styles | Premium responsive XenForo styles

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

Re: Template system: alternative syntax for DEFINE

Post by callumacrae » Thu Apr 11, 2013 9:27 pm

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 » Wed Dec 10, 2014 4:31 pm

+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: 1724
Joined: Thu Mar 02, 2006 4:29 pm
Location: Earth
Contact:

Re: Template system: alternative syntax for DEFINE

Post by DavidIQ » Wed Dec 10, 2014 8:26 pm

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