Instead of template.php , let's include template*.php

CommentFileSizeAuthor
template_includes.patch491 byteschx

Comments

Tobias Maier’s picture

do I read your patch the false way or do you include all template.*.php files?

why do you want to have this this?

chx’s picture

that's template*.php and it's needed so that people can easily redistribute template.php chunks. Think flatforum -- there will be more IMO because of form API.

Tobias Maier’s picture

youre right +1

but maybe to it would be nice to have a naming covention for this files:
i would like it if only the template.php and all template_*.php would be included

Cvbge’s picture

This means you need to scan whole directory. What about performance?

I'm not template guy, so I don't understand your explanations. Could you explain more clearly how would this benefit users?

morbus iff’s picture

+1 to this. Tobias: using underscores is a bad idea, as it breaks with phptemplate tradition; you create "node.forum.tpl.php", not "node_forum.tpl.php" to theme forums, for example.

Tobias Maier’s picture

whats going on with this?

I think it is a good function because it allows us to implement code snippets in a fast way, so users can start to creat template*.php collections which allows them to reuse parts of them very fast

adrian’s picture

I would +1 this, as I really like the functionality .. but I don't think we should be running file_scan_directory(dirname($template->filename), 'template.*\.php')) for every page load.

It's very likely quite expensive, although I have no metrics to base this on (other than it being one of the most expensive calls on admin/modules).

varunvnair’s picture

How about maintaining a list of template*.php files someplace (in the database or a file) and refreshing this list only when admin visits the themes configuration page. This might help improve performance.

varunvnair’s picture

How about maintaining a list of template*.php files someplace (in the database or a file) and refreshing this list only when admin visits the themes configuration page. This might help improve performance.

markus_petrux’s picture

The same way there's an input format that allows you to "write" code, what about another input format that allows you to "include" PHP code? If the location is known, even a drop down could easily allow you to select scripts.

...just an idea, if it's about code snippets.

Jaza’s picture

Version: x.y.z » 6.x-dev
Status: Needs review » Needs work

Moving to 6.x-dev queue.

I don't really think this is needed. If themers want to split up their template.php, then they can manually include_once their extra template*.php files inside template.php.

Or maybe a better idea would be to have a mythemename_include_files() function that you could put in template.php, that would return an array of template*.php files to include. Not much different to including them manually, but it would make including a bit easier, and it would encourage people to split up their template.php, simply because the hook/callback mechanism is there.

Crell’s picture

Remember that include()ing lots of files creates a bigger performance hit that including one big file. It's more disk IO, and disk IO == slow. Encouraging people to split up template.php into lots of files only increases the disk IO and hurts performance. If you're doing enough code in template.php that you really do need to split it up for manageability reasons, then you should know enough about PHP and Drupal that you can do your own list of includes at the top of the file and be done with it.

morbus iff’s picture

Crell, Jaza: you're missing the goal of this feature. Consider a module that ships with a template.modulename.php file and instructs the user to place it in their theme directory. Now, the module can ship with specific core theme overrides that make it all purdy and useful by default. Granted, without this feature, the module could still do that, but the themer would be given another instruction: to add the include_once manually to their template.php, which presumes that they even HAVE a template.php. The goal here is not to encourage the themer to split up their stuff into multilple file chunks: the goal is to make it easier for modules to ship with theme overrides that value-add its capabilities.

RobRoy’s picture

Yeah, +1 on what Morbus said.

chx’s picture

Status: Needs work » Fixed

module preprocess nicely fits the bill

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.