[RFC|Merged] Unlimited styles tree (template inheritance)

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.
Post Reply
User avatar
Arty
Former Team Member
Posts: 985
Joined: Wed Mar 06, 2002 2:36 pm
Location: Mars
Contact:

[RFC|Merged] Unlimited styles tree (template inheritance)

Post by Arty »

This RFC is addition to [RFC] Merge style components, [RFC] Revamp of styles section of acp and possibly [RFC] <!-- RESOURCE --> template tag.

Description

Currently template inheritance is only 2 levels deep:

Code: Select all

prosilver
- style that inherits from prosilver
But sometimes it would be nice to have more levels of template inheritance:

Code: Select all

prosilver
- custom style
- - custom style with fixed width
- custom framework based on prosilver
- - style based on custom framework
- - - modified style based on style above
Additionally I suggest to rename "inheritance" to "parent" and "child" styles. That sounds less confusing.

Pros

1. Maintaining styles becomes a bit easier.

Instead of customizing style, user can create child style and customize it instead, then during update he only has to replace parent style and possibly tweak his customizations. Example tree:

Code: Select all

prosilver
- awesomesilver
- - custom style
2. It is already almost implemented.

It might look like a lot of work, but it isn't. New template system is already designed to handle this. I'm building new acp_styles with ability of unlimited trees in mind, so this function is already almost implemented.

Implementation will require:
  • Increasing length of style_inherit_path field.
  • Adding few lines of code to template engine.
  • Removing some safety checks in acp_styles that currently do not allow installation of style if parent style already has a parent style.
So it is very easy to implement.

Cons

I don't see any.

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

Re: [RFC] Unlimited styles tree (template inheritance)

Post by DavidIQ »

Arty wrote:Cons

I don't see any.
Could be a support nightmare especially for MOD authors. However with template hooks that might not be too bad.
+1
Image

User avatar
Arty
Former Team Member
Posts: 985
Joined: Wed Mar 06, 2002 2:36 pm
Location: Mars
Contact:

Re: [RFC] Unlimited styles tree (template inheritance)

Post by Arty »

DavidIQ wrote:Could be a support nightmare especially for MOD authors. However with template hooks that might not be too bad.
+1
I have an idea that might help with that: in acp_styles when editing templates instead of select box, show template tree that lists all templates, including templates in parent styles. Something like this:

Code: Select all

Select template to edit:
--------------------------------
| template name      | customized in | actions |
| index_body.html    | this style        | edit, revert |
| overall_header.html     | this style        | edit, revert |
| mcp_header.html    | prosilver        | customize |
--------------------------------

User avatar
brunoais
Registered User
Posts: 964
Joined: Fri Dec 18, 2009 3:55 pm

Re: [RFC] Unlimited styles tree (template inheritance)

Post by brunoais »

^ I quite didn't figure out what you are stating.

User avatar
Arty
Former Team Member
Posts: 985
Joined: Wed Mar 06, 2002 2:36 pm
Location: Mars
Contact:

Re: [RFC] Unlimited styles tree (template inheritance)

Post by Arty »

brunoais wrote:^ I quite didn't figure out what you are stating.
You need to be familiar with how template inheritance works in 3.0 to understand this. Then you need to be familiar with other forum systems that use similar functionality and use tree structure for styles to see how it works. Then you need to play with their styling system to appreciate advantages tree system provides.

Example of a styles structure I'm using on one of my client's forums:
- Master Style (main style)
- - Custom Colors (css and images modified via colorizeit)
- - - Template Changes (layout moved around)
- - - - Printing Functionality (includes additional css for "@media print")
- - - - - Banner Ads (only templates that have banners)
- - - - - - Forum Style (final forum style, doesn't include anything)

That forum uses another forum software that supports multiple levels of template inheritance. All styles other than last style are not available for selection by user (similar to deactivated styles in phpbb).

Advantages of doing it:
- Updating forum? I'll just replace master style
- Changing color scheme? I'll just replace "custom colors" style
- Want to customize layout more? I'll edit "template changes" style
- Want to update banner ads? I'll just replace "banner ads" style

I want to give phpBB forum admins ability to do similar stuff.

How much coding does it require to implement? In includes/template/template.php replace functions set_template() and set_custom_template() with this

Code: Select all

	public function set_template()
	{
		$template_name = $this->user->theme['style_path'];
		$fallback_name = ($this->user->theme['style_inherits_id']) ? array_reverse(explode('/', $this->user->theme['style_inherit_path'])) : false;

		return $this->set_custom_template(false, $template_name, false, $fallback_name);
	}
(only 1 line was changed)

Code: Select all

	public function set_custom_template($template_path, $template_name, $fallback_template_path = false, $fallback_template_name = false)
	{
		$templates = array($template_name => $template_path);

		if (is_string($fallback_template_name))
		{
			$templates[$fallback_template_name] = $fallback_template_path;
		}
		if (is_array($fallback_template_name))
		{
			$i = 0;
			foreach ($fallback_template_name as $fallback_template_name_item)
			{
				$templates[$fallback_template_name_item] = is_array($fallback_template_path) ? $fallback_template_path[$i] : $fallback_template_path;
				$i ++;
			}
		}

		$this->provider->set_templates($templates, $this->phpbb_root_path);
		$this->locator->set_paths($this->provider);
		$this->locator->set_main_template($this->provider->get_main_template_path());

		$this->cachepath = $this->phpbb_root_path . 'cache/tpl_' . str_replace('_', '-', $template_name) . '_';

		$this->context = new phpbb_template_context();

		return true;
	}
(1 line changed, 7 new lines of code)

That's it. Very simple implementation.

User avatar
brunoais
Registered User
Posts: 964
Joined: Fri Dec 18, 2009 3:55 pm

Re: [RFC] Unlimited styles tree (template inheritance)

Post by brunoais »

Arty wrote:
brunoais wrote:^ I quite didn't figure out what you are stating.
You need to be familiar with how template inheritance works in 3.0 to understand this. Then you need to be familiar with other forum systems that use similar functionality and use tree structure for styles to see how it works. Then you need to play with their styling system to appreciate advantages tree system provides.
The problem was only the part inside the code tags.
Anyway, that seems a great addition for our 3.1 :)

User avatar
Arty
Former Team Member
Posts: 985
Joined: Wed Mar 06, 2002 2:36 pm
Location: Mars
Contact:

Re: [RFC] Unlimited styles tree (template inheritance)

Post by Arty »

Some other code changes (apart from template changes I listed above):

Database structure changes (+merging style components changes):
1. phpbb_templates:template_inherit_id -> phpbb_styles:style_parent_id
2. phpbb_templates:template_inherits_from -> phpbb_styles:style_parent_path

style_parent_path is also changed to "text" to allow unlimited length. Items in value are separated with "/", for example: "prosilver/custom_style"

And in PHP code posted above replaced style_inherit_path with style_parent_path and style_inherits_id with style_parent_id

And that's all. Very simple change. Got it working and thoroughly tested it.

User avatar
Arty
Former Team Member
Posts: 985
Joined: Wed Mar 06, 2002 2:36 pm
Location: Mars
Contact:

Re: [RFC] Unlimited styles tree (template inheritance)

Post by Arty »

It was very easy to implement (ether this or I'd have to write a lot of new useless code that would be replaced later anyway) during implementation of [RFC] Merge style components, therefore it is included in pull request for that RFC.

User avatar
Arty
Former Team Member
Posts: 985
Joined: Wed Mar 06, 2002 2:36 pm
Location: Mars
Contact:

Re: [RFC|Merged] Unlimited styles tree (template inheritance

Post by Arty »

Moved topic from 3.2 RFCs to 3.1 because this RFC was merged as part of [RFC|Merged] Merge style components

Post Reply