phpBB

Development Discussion Board

phpBB's testing ground of bleeding edge code
Advanced search

Consolidating templates

Discuss the future of phpBB. It is still nesting in its mother's womb, but it will grow a little bigger each day. Participate in its design & planning here.

Consolidating templates

Postby Arty » Fri Dec 30, 2011 11:04 am

In phpBB 3 same code is used in many places, making it very complex to customize style. For example, post template is used in viewtopic_body, posting_preview, posting_review, ucp_pm_viewmessage.

I suggest to consolidate similar templates into single template file:

  • Posts: template "posts". It should be used for posts, private messages, post preview, post view in mcp, etc... anything where post is shown.
  • Forums list: template "forums". It should be used for forum index, subforums list in forum view, moderator control panel, bookmarks in ucp, search results and other parts of forum where forums list is shown.
  • Topics list: template "topics". It should be used for topics list when viewing forum, mcp, bookmarks, search results, etc. It should also be used for private messages list.

All of those templates will have loops to display all items, so it would be easier to add global header and footer for whole block.

Such concept should also make it easier to create php code because it can be assigned to a single class. Something like phpbb_post::display()
Formerly known as CyberAlien.
User avatar
Arty
Styles Team
Styles Team
 
Posts: 796
Joined: Wed Mar 06, 2002 2:36 pm
Location: Mars

Re: Consolidating templates

Postby imkingdavid » Fri Dec 30, 2011 2:23 pm

That's a good idea. Reducing code duplication is usually a good thing to do. Of course, it can be limiting because it makes it somewhat more difficult to customize, for instance, PM pages to be slightly different from topic view pages.
I do custom MODs. PM for a quote!
View My: MODs | Portfolio
Please do NOT contact for support via PM or email.
Remember, the enemy's gate is down.
User avatar
imkingdavid
Development Team
Development Team
 
Posts: 902
Joined: Thu Jul 30, 2009 12:06 pm

Re: Consolidating templates

Postby MichaelC » Fri Dec 30, 2011 2:43 pm

imkingdavid wrote:It can be limiting because it makes it somewhat more difficult to customize, for instance, PM pages to be slightly different from topic view pages.


+1 to this bit of your post.

Its a good idea but doing this would remove some of the things which make phpBB so easy to customise whatever you want.
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
MichaelC
Website Team
Website Team
 
Posts: 797
Joined: Thu Jan 28, 2010 6:29 pm

Re: Consolidating templates

Postby Arty » Fri Dec 30, 2011 3:11 pm

I think its the other way around: having too many different templates makes it difficult to customize phpBB. If style author would want to have a unique post layout, he'd have to edit 10+ templates, which produce almost the same thing, but with few tweaks. Then mods have to add code to several templates, which all could have been customized by style author, making mod installation a nightmare to forum owners.

If instead of those 10+ templates there is only 1, everyone would have to apply changes to only that one template.

Conditional statements aren't going away, there can still be different layouts of same item for different parts of forum. So you can have different layouts for private message, post, news article (for some mod), calendar event (also for some mod) or whatever else could be displaying data like post, while allowing style author to customize all of them by editing one template file.
Formerly known as CyberAlien.
User avatar
Arty
Styles Team
Styles Team
 
Posts: 796
Joined: Wed Mar 06, 2002 2:36 pm
Location: Mars

Re: Consolidating templates

Postby DavidIQ » Fri Dec 30, 2011 4:46 pm

I know you've been dealing with installing Titania as of late so maybe you've noticed how the style is set up for it. It starts with the default folder and anything that needs to be customized is copied into the custom template directory (in our case "prosilver"). I think this approach might be best for this proposal pretty much taking template inheritance to the next level and even simplifying it.
Image
User avatar
DavidIQ
MOD Team Leader
MOD Team Leader
 
Posts: 759
Joined: Thu Mar 02, 2006 4:29 pm
Location: Earth

Re: Consolidating templates

Postby imkingdavid » Fri Dec 30, 2011 4:52 pm

We could do something like Twig's block system, where you can set a default template block and overwrite it as needed.
I do custom MODs. PM for a quote!
View My: MODs | Portfolio
Please do NOT contact for support via PM or email.
Remember, the enemy's gate is down.
User avatar
imkingdavid
Development Team
Development Team
 
Posts: 902
Joined: Thu Jul 30, 2009 12:06 pm

Re: Consolidating templates

Postby Arty » Fri Dec 30, 2011 5:02 pm

Template inheritance is great, but it solves a completely different problem. It doesn't solve problem of having same content in many template files. It doesn't even help when I want to customize small part of template because I still have to copy whole template before applying changes. It only helps to create styles that are minor modifications of default style, which is completely opposite to goal of this suggestion. Goal of this suggestion is to make it easier to completely redesign layout.

Here is a better example of what I'm proposing.

Example: post layout. Private message is basically a post, without forum assigned to it and with recipient data. Post preview is also a post. Topic review is a list of posts. Search results page is ether list of topics or list of posts. All of them have different templates that have the same purpose: to display a post. So why not use one template for it? A post is a post. There is no need to have several templates that serve the same purpose.

imkingdavid wrote:We could do something like Twig's block system, where you can set a default template block and overwrite it as needed.

I think that's close to what I'm suggesting. I'll check it
Formerly known as CyberAlien.
User avatar
Arty
Styles Team
Styles Team
 
Posts: 796
Joined: Wed Mar 06, 2002 2:36 pm
Location: Mars

Re: Consolidating templates

Postby Arty » Fri Dec 30, 2011 5:21 pm

imkingdavid wrote:We could do something like Twig's block system, where you can set a default template block and overwrite it as needed.

It does serve that purpose, but not by itself. What I'm suggesting is mix of blocks and includes. Like this (don't mind errors in code, I'm not familiar with twig enough to write correct code yet):

Topic page:
Code: Select all
{% extends "main.html" %}
{% block content %}
    {% block posts_header %}
         topic title, mcp link, etc
     {% endblock %}
    {% block posts %}
         {% include "posts.html" }
    {% endblock %}
    {% block posts_footer %}
          quick reply, buttons, etc
    {% endblock %}
{% endblock %}

Private message (I'd go even further by including viewpm.html instead of showing blocks, but for this example I won't make it that complex):
Code: Select all
{% extends "ucp.html" %} <!-- (ucp.html extends main + ucp header / footer) -->
{% block content %}
    {% block post_header %}
         post title
     {% endblock %}
    {% block post %}
         {% include "post.html" }
    {% endblock %}
    {% block post_footer %}
          quick reply, buttons, etc
    {% endblock %}
{% endblock %}


then posts.html:
Code: Select all
{% block post_start %}
<div class="posts-list">
{% blockend %}
{% for post in posts %}
    {% include "post.html" %}
{% endfor %}
{% block post_end %}
</div>
{% blockend %}

and post.html:
Code: Select all
{% block post_wrapper_start %}
<div class="post" {% if post.id %} id="{{ post.id }}"{% endif %}>
{% endblock %}
{% block post_poster_profile %}
     poster profile here
{% endblock %}
{% block post_content %}
    post content here, with nested blocks for bbcode, attachments, etc
{% endblock %}
{% block post_wrapper_end %}
</div>
{% endblock %}


Topic includes posts.html that loops through post.html to display posts
Private message includes post.html to display message.

In the end both functions use the same file: post.html, which displays post content. I'm suggesting to do the same for all block that can be reused: have only one global template for it.
Formerly known as CyberAlien.
User avatar
Arty
Styles Team
Styles Team
 
Posts: 796
Joined: Wed Mar 06, 2002 2:36 pm
Location: Mars

Re: Consolidating templates

Postby callumacrae » Fri Dec 30, 2011 6:00 pm

Does Twig implement the Django template language in PHP?

I <3 the Django template language syntax :D
"In JavaScript, there is a beautiful, elegant, highly expressive language that is buried under a steaming pile of good intentions and blunders"
—Douglas Crockford

View my MOD, phpBB Mobile
User avatar
callumacrae
Website Team
Website Team
 
Posts: 883
Joined: Tue Apr 27, 2010 9:37 am
Location: England

Re: Consolidating templates

Postby Arty » Fri Dec 30, 2011 8:11 pm

DavidIQ wrote:I know you've been dealing with installing Titania as of late so maybe you've noticed how the style is set up for it. It starts with the default folder and anything that needs to be customized is copied into the custom template directory (in our case "prosilver"). I think this approach might be best for this proposal pretty much taking template inheritance to the next level and even simplifying it.

Actually, Titania does close to what I'm suggesting. Lots of includes, nice directory structure. Didn't look close enough at template files before, so I didn't notice. :P
Formerly known as CyberAlien.
User avatar
Arty
Styles Team
Styles Team
 
Posts: 796
Joined: Wed Mar 06, 2002 2:36 pm
Location: Mars

Next

Return to [4.x] Discussion

Who is online

Users browsing this forum: No registered users and 10 guests