Author Topic: Module template locations  (Read 184 times)

Offline Fustrate

  • Aldo the Apache
  • Hero Member
  • Posts: 733
  • Gender: Male
  • Noxious Boxes
    • Fustrate
Module template locations
« on: June 16, 2010, 01:47:58 PM »
So Dragooon and I were talking last night, and we came to a stand-still on where each module's template files should be. I'll try to explain both options as fully as possible,

Option 1: In module
Code: [Select]
/modules
/hello_world
/templates
/default
/example.tox
/i_like_cheese.tox
/ugly_theme
/example.tox
...
/themes
/default
/compiled
/.toxg.core_common.php
/.toxg.core_index.php
/.toxg.hello_world_example.php
/.toxg.hello_world_i_like_cheese.php
/core
/common.tox
/index.tox
/css
/style.css
/ugly_theme
/compiled
/.toxg.core_common.php
/.toxg.hello_world_example.php
/core
/common.tox
/css
/style.css
Called via Core::$theme->loadTemplates(absolute or relative path to .tox file). No extra moves are necessary, as everything is contained in the module folder.



Option 2:
Code: [Select]
/themes
/default
/compiled
/.toxg.core_common.php
/.toxg.core_index.php
/.toxg.hello_world_example.php
/.toxg.hello_world_i_like_cheese.php
/core
/common.tox
/index.tox
/css
/style.css
/hello_world
/example.tox
/i_like_cheese.tox
/ugly_theme
/compiled
/.toxg.core_common.php
/core
/common.tox
/css
/style.css
/hello_world
/example.tox
called via Core::$theme->loadTemplates('hello_world/i_like_cheese'). When installing a module, the .tox files would all be moved to the {module_name} folder in /themes/default/, and would be deleted when the module is removed via the admin panel.



So ya, which one would we rather go with?

(@Dragooon - if I got anything wrong, please edit this post.)

Offline xycose

  • Full Member
  • Posts: 114
Re: Module template locations
« Reply #1 on: June 16, 2010, 01:51:16 PM »
I think option one could be less confusing for some.

Offline Dragooon

  • Sr. Member
  • Posts: 485
Re: Module template locations
« Reply #2 on: June 16, 2010, 11:58:30 PM »
@Option 1 - We can simply do a Core::$theme->loadTemplate('module_name', 'template_name') or Core::$theme->loadTemplate($this(Module instance), 'template_name'); rather than giving in an absolute path.
I've been posting quite useless posts quite happily.

Offline Fustrate

  • Aldo the Apache
  • Hero Member
  • Posts: 733
  • Gender: Male
  • Noxious Boxes
    • Fustrate
Re: Module template locations
« Reply #3 on: June 17, 2010, 02:22:44 AM »
We'd then need to differentiate between templates loaded from a module and templates loaded from the core, since they're located in two different places.

I like option 2 for its simplicity of all template files being in one place, sorted by what they belong to. I know modules will be added just by uploading a folder and running a script, but why can't that script move the /templates/ folder to /themes/default/{module_name}/? Seems like a smart installer/uninstaller would know where to put/find everything, so there's no problem there.

Offline Lorel

  • Jr. Member
  • Posts: 57
Re: Module template locations
« Reply #4 on: July 23, 2010, 04:14:22 PM »
Putting all the templates in one place has an advantage - you know where it is. But at the same time, you have to be not merely smart, but very smart with resources.

The problem you get is if two modules share a template that isn't a core template, since both will be dropping their own in the master themes space, and when one module is removed, the shared template is also removed. I also see no reason why you couldn't have modules that depend on modules (that's something else to discuss, I think)

So while it would likely be more performant to put everything in one place, there are some major issues around doing so that make me wonder if it isn't cleaner to keep a module all together in one place (though noting the caveat still of having dependent modules... ugh)

If you're passing a reference to the module through to the template loader, no matter how abstractly that appears to be, it seems there is still enough being passed through that you could identify the location of the template?

Offline Xarcell

  • Semi-Newbie
  • Posts: 31
Re: Module template locations
« Reply #5 on: July 24, 2010, 05:14:38 AM »
I'm for templates being located in one place as well.

 
If one module is removed and is sharing a template file, the shared file should not be removed unless no other module is sharing it.(should be a check for this)

Offline Lorel

  • Jr. Member
  • Posts: 57
Re: Module template locations
« Reply #6 on: July 24, 2010, 05:22:24 AM »
Presumably then each module would on activation or installation, register a list of templates that it uses?

Offline Xarcell

  • Semi-Newbie
  • Posts: 31
Re: Module template locations
« Reply #7 on: July 24, 2010, 05:24:03 AM »
Most likely on installation I think is best.

Offline Lorel

  • Jr. Member
  • Posts: 57
Re: Module template locations
« Reply #8 on: July 24, 2010, 06:07:12 AM »
Provided that whatever 'remove' options also ensure the registry of templates is cleaned up, or there is a review option or something, that should be OK.

Offline Fustrate

  • Aldo the Apache
  • Hero Member
  • Posts: 733
  • Gender: Male
  • Noxious Boxes
    • Fustrate
Re: Module template locations
« Reply #9 on: August 19, 2010, 10:42:11 AM »
I'm now thinking that I agree with Dragooon - templates should remain with the module, and the module just feeds an absolute path to the templating system.

Offline [Unknown]

  • Hero Member
  • Posts: 1936
Re: Module template locations
« Reply #10 on: August 20, 2010, 12:59:22 AM »
Ultimately, if I'm going to right "NiftyTheme", having to place my files all over the place is a mistake.  However, on the other side, module developers having their templates mixed with the "core" templates is also a mistake.

TOX-G supports defaulting/inheriting of templates, which may apply to this discussion.

When you send a template into the system for compiling, you can actually send a list of files.  Let's suppose you had the following files:

Code: (themes/default/blah.tox) [Select]
<tpl:template name="jaelta:blah1" />
<tpl:template name="jaelta:blah2" />
<tpl:template name="jaelta:blah3" />

Code: (themes/theme1/blah.tox) [Select]
<tpl:template name="jaelta:blah1" />

Code: (themes/theme2-based-on-theme1/blah.tox) [Select]
<tpl:template name="jaelta:blah2" />

If you sent them in reverse order of what I just said above, the resulting output would contain blah1 from theme1, blah2 from theme2-based-on-theme1, and blah3 from default.

In the same way, you might have the following templates:

modules/hello_world/templates.tox
themes/ugly_theme/modules/hello_world/templates.tox

Ultimately, I think it's a mistake for the module developer to create theme-specific templates.  Instead, they should use overlays or existing templates for those cases.  This is why a "library" of ui-widgets in the theme makes sense (which would be the primary thing a new theme would override, inheriting from its parents.)

So, normally, I don't see this being a problem personally - hello_world should, if possible, have theme agnostic templates.  In the rare case that a theme author wants to override them, they should be able to do so within the theme.

But, that's just my point of view.  I think the decision on this one way or another needs to consider:

1. Where modules' templates go.
2. Where themes' templates go.
3. Who is ultimately in control of the templates (who is more important.)
3.1. Where modules' theme-specific templates go, if they are possible.
3.2. Where themes' module-specific templates go, if they are possible.
4. The same questions above for overlays, if they are used.

-[Unknown]