Jump to content
Matt
 Share


IPB 3: Making Templating Easier

HTML logic has been a feature of Invision Power Board for quite some time now. Although we didn't make much use of the '<foreach>' tag so that skins could be backwards compatible, we did make good use of the <if> <else /> logic. Now that we have a clean slate with v3.0, we can really make some positive changes.

Invision Power Board 3.0 makes full use of the existing HTML logic and adds some more functionality. This allows for some dramatic customization without touching any of the PHP code. Where possible, each 'view' (board index, topic listing, viewing a topic) has a single template. Previous versions 'stitched' together several templates (as many as 30!) to create a single page view. This meant that some items were fixed and unable to be moved. For example, on the board index, it was not possible to move the board stats above the list of forums. Likewise it was not possible to move the active users below the board statistics.

Now you can. You can move any item to any place for that view without having to edit the PHP files themselves. This will really open up designer's creativity and allow some really unique looking templates.

Another leap forward for Invision Power Board 3 is the ability to use display logic in the templates themselves. Naturally, we were always able to use <if> and <else /> but you can now use the following standard tags:

The Date Tag:
Examples:

{%date="1210012321"|format="manual{d m Y}"%} {%date="-1 day"|format="long"%}

{%date="now"|format="long"|relative="false"%}



For the first time, you can now explicitly specify a date format on a per-use basis. The tag accepts either a unix 'timestamp' or a human string like 'now', '-1 day', 'tomorrow', etc. The format parameter can either be a standard IPB date format (long, short, joined, etc) or a manual PHP Date format.

The Parse Tag:
Examples:

<parse expression="substr( $data['name'], 0, 10 )" />

<parse expression="sprintf( "14", "There are %s apples in the bag" )" />



This parse tag allows you to make on-the-spot parsing using PHP code. This tag is replaced with the value returned from PHP.

The URL Tag:
Examples:

{%url="foo=1&bar=2"|base="public"%}

{%url="foo=1&bar=2"|label="Click Me"|base="public"|id="myLink"|class="linkCSS"|onclick="this.function()"%}



The first example will actually create the entire <a href='' ... >...</a> HTML chunk whereas the second example will only return a formatted URL. The main reason for this tag is to prevent hardcoded entire URLs or even fixing part of the URL to a setting. In IPB 2.3 it wasn't unusual to see this:

<a href='{$this->ipsclass->base_url}&act=login'>Log In</a>



The new method would be like so:

<a href='{%url="act=login"|base="public"%}'>Log In</a>



The 'base' value being 'public' tells the template engine to use the public URL and not the ACP url. The real power of this feature lies in the return value being automatically fed via formatURL() which can return a friendly URL if friendly URLs are enabled.

The Variable Tag:

Example:

<variable key="tdColor" oncondition="$foo == "green"" value="green" /> <variable key="tdColor" oncondition="$foo == "black"" value="black" /> <span style='color:<variable="tdColor" />'>Hello World!</span>

<variable key="tdColor" default="blue" />





In this example, depending on $foo having a value of green:

<span style='color:green'>Hello World!</span>



This tag allows you to decide in the template itself how part of the template should display without having to edit PHP code. This is a handy tag for use in foreach blocks to alternate between colours when showing posts, topics, etc.

Custom Tags
The tags URL and date tags shown above use the {%tag="foo"|param="bar"%} format. These are actually custom plug-ins. You can write your own custom plug ins and they are available immediately within the templates. You could even modify the default plug-ins to change their behaviour.

We're looking forward to how these new tools are used in your own templates!

 Share

Comments

Recommended Comments



I hope there will be a lot of documentation on this stuff because I understood some of what that said but even as savvy as I am I'm going to have to fully understand it and I'm not quite sure what all the stuff in those tags are for.

Link to comment
Share on other sites

Every single thing will seem complicated at the beginning, Just like the components were when they first introduced. But with a good documentation anything will be possible. I just hope they will make a good documentation for the upcoming 3.0 changes.

Link to comment
Share on other sites

Thank you!
This will make modding so much easier, and maintaining modifications as I can see a some edits not being required with the advanced logic. All of it (except the url tags, but that will be needed now friendly urls exist) I have thought life would be easier if it were possible.

Link to comment
Share on other sites

[quote name='Complete-Servers' date='May 15 2008, 04:01 PM']Hello,

Is there any idea on public beta releases or final public releases of the new IPB 3

Andy Rixon
When it's ready :) But I believe the first blog post said "Q4".

Link to comment
Share on other sites

Ahhh, this is great news! Was exactly the direction I was hoping you would take with templates for v3.

Do you have any idea how many templates you're going to be able to get rid of?

Link to comment
Share on other sites

Greetings, colleagues.
I think many designers can tell you very much for this improvement :)

Interested in the question: how will I editing such a large template? Will this be supported by forum ACP or can be edited as a template file?

Sorry for my English.

Link to comment
Share on other sites

[quote name='Alεx' date='May 16 2008, 10:51 AM']I'm really eager to see how you got it down to one template, will that mean a lot more data is parsed into the template? But yeah, sounds good
It's probably like the personal portal main and show member list templates are now; all the code for the page is self-contained so you can move it around and do as you wish. This is something I like! A few of the components I've written I've done much the same thing utilizing foreach tags to not have three hundred templates for a simple table.

I don't quite understand the URL tag being changed in this manner. Seems like it's making it far more complex than it needs to be, but then again, I'm used to writing out anchor tags. Maybe to people that are not it's something easier to use? :/

Show us the template manager!

Link to comment
Share on other sites

[quote name='Matt' date='May 16 2008, 07:33 AM']Dan, a lot! Topic view (viewing posts) is down from 40+ to 1. Board Index is down 20+ to 1, Forum Index is down from over a dozen to 1.

WOW MATT damn good work this also might cut down on total queries each page has when loading

I can not wait to see calender and other act pages that have more then 1 template

Link to comment
Share on other sites

With the parse tag, how have you managed to keep it secure? For example, what's to stop a user who only has limited ACP access (but access to edit templates) from using the parse tag to parse code which would give them elevated rights?

Link to comment
Share on other sites




Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...