When theming a page, PHPTemplate (and possibly others) offer suggestions based on the uri. This is a handy feature but when dealing with arguments that are integers, either you have to theme the previous suggestion or the specific one eg.

page-user.tpl.php or page-user-1.tpl.php

this is a bit cumbersome because I want to theme all the user profile pages but to do that I have to override page-user.tpl.php but then faced with the problem that the user login page now is themed as well.

What this patch do is provide a wildcard for integer arguments like page-user-*.tpl.php. Suggestions which have additional arguments like page-user-edit.tpl.php remain the same; this simply differentiates the suggestions with and without integer args.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

evil_marty’s picture

FileSize
445 bytes

My apologies, ignore the asterix in the file, I forgot that that character is illigal in the most filesystems, I've updated it to the tild ~ character.

Crell’s picture

Version: 5.2 » 7.x-dev

Drupal 5 is no longer taking new features. Drupal 6 is currently frozen for refinement, so it's unlikely that this will get in. Moving to the Drupal-7 queue.

That said, it sounds like interesting functionality.

dvessel’s picture

Status: Needs review » Needs work

Definitely a neat idea and it wouldn't break anything in 6. ;)

deekayen’s picture

Status: Needs work » Needs review
FileSize
657 bytes

Same patch ported to the new D7 location.

Status: Needs review » Needs work

The last submitted patch failed testing.

deekayen’s picture

Status: Needs work » Needs review
FileSize
2.76 KB

Updates tests that failed for recognizing the new wildcard options being returned.

Status: Needs review » Needs work

The last submitted patch failed testing.

deekayen’s picture

Status: Needs work » Needs review
FileSize
2.76 KB

Updating for failed tests.

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

Seems like a no-brainer to me. Well done. Lets wait for a healthy test bot to check this. If it does not reset status, we are good.

deekayen’s picture

I know I shouldn't touch it, but I couldn't help but add the following inline docs:

+    // The tilde acts as a wildcard for numeric arguments since
+    // asterisks are not valid filename characters on many filesystems.

Status: Reviewed & tested by the community » Needs work

The last submitted patch failed testing.

deekayen’s picture

Status: Needs work » Needs review

I think this is from a bad patch that got committed.

deekayen’s picture

Status: Needs review » Reviewed & tested by the community

moshe had it rtbc

webchick’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: +Needs themer review

This is interesting! Tagging for themer review to get a pair or two of affected pair of eyes on this, although dvessel has already given it a thumbs-up above.

To me, the ~ and - are very difficult to distinguish visually. I understand why asterisks can't be used, but I wonder if we could use a different character. Is there by chance a character in CSS/HTML/JS other than * that would be synonymous with "stuff here"? Maybe % because that's a wildcard in SQL?

deekayen’s picture

Assuming it keeps support for strangely old filesystems, the DOS 8.3 spec says the character limits are:

! # $ % & ' ( ) - @ ^ _ ` { } ~

That means the % would be a valid alternative, however going all the way back to Windows 3.1.1, filenames that exceeded the 8 character limit were shortened by replacing characters with the tilde as the wildcard, so it's not as if it's without historic continuity:

It's not just Windows 3.x either. When Windows 2000 shares files to other old-ish machines, it shortens the filename with a tilde.

http://technet.microsoft.com/en-us/library/cc938923.aspx

I don't know what OS or filesystem commonly shortens filenames with %.

Disclaimer: I haven't developed Drupal on Windows in years.

Damien Tournoud’s picture

It makes sense to use "%". Let's do that ;)

stephthegeek’s picture

Clever! Big thumbs up.

Ditto with the %. -~ is too awkward.

deekayen’s picture

Here's a % version.

Manuel Garcia’s picture

A very nice innitiative!

I'm more of a themer myself, so forgive me if this is nonsense from a developer point of view. My comment is about the wildcard character, thinking about usability, would it be possible to have the wildcard be 'all' instead of a '%' ? so we could use tpls like page-user-all.tpl.php.

I think it would be best understood and immediately grasped by the themers, but again, no clue if this is even a possibility - either way, i hope this gets in for d7 =))

deekayen’s picture

Technically it's possible to have all instead, but then you couldn't have any paths with "all" in them that wouldn't confuse the wildcard. Having the patch /page/user/all would confuse the rule.

Manuel Garcia’s picture

ah, excelent point... nevermind =)

ultimateboy’s picture

Status: Needs review » Reviewed & tested by the community

Although I don't really think it will be used all that often, there is a definite use case and this solves it quite nicely. From a themer's perspective, I like the implementation.

deekayen’s picture

In anticipation of the commit, here's some documentation for http://drupal.org/update/theme/6/7

Nav link:

<li><a href="#phptemplate-suggestion-wildcard">PHPTemplate suggestion wildcard</a></li>

Body:

<h3 id="phptemplate-suggestion-wildcard">PHPTemplate suggestion wildcard</h3>
<a href="http://drupal.org/node/167112">(issue)</a> <p>PHPTemplate offers suggestions based on the URI integers. In Drupal 6, you have to theme the previous suggestion or the specific one eg.

page-user.tpl.php or page-user-1.tpl.php

This was cumbersome because to theme all the user pages, it meant overriding page-user.tpl.php, which in turn themed the user login page.

The new suggestion wildcard for integer arguments accepts % suggestions page-user-%.tpl.php. Suggestions which have additional arguments like page-user-edit.tpl.php remain the same; this simply differentiates the suggestions with and without integer args.</p>
Zarabadoo’s picture

Status: Reviewed & tested by the community » Needs review

I am also in favor of this.

Zarabadoo’s picture

Status: Needs review » Reviewed & tested by the community

I really need to remember to full page refresh before I comment on something. Status fixed.

webchick’s picture

Status: Reviewed & tested by the community » Needs work

Wow, nice patch AND docs in advance? I'm in love. ;)

Hm. I was going to commit this but I got:

patching file includes/theme.inc
patching file modules/simpletest/tests/theme.test
patch unexpectedly ends in middle of line
Hunk #1 succeeded at 27 with fuzz 1.

Could someone do a quick re-roll please?

deekayen’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
2.9 KB

Minty fresh.

webchick’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: -Needs themer review +Needs documentation

Awesome, thanks! :)

Committed to HEAD. If someone could stick those nice docs into the theme upgrade guide that'd be lovely!

deekayen’s picture

Status: Needs work » Fixed
Issue tags: -Needs documentation

docs saved from #23

mattyoung’s picture

subscribe

Status: Fixed » Closed (fixed)

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

Shane Birley’s picture

Does this latest patch work on D6? Or was it D7 only?

deekayen’s picture

It probably doesn't apply exactly, but since it was originally written for 5.2, I bet you could add it to 6.x.

Shane Birley’s picture

Cool. I will take a gander at the code and see if it would be quick to port.

sign’s picture

seemed like the docs were a bit outdated, so did a small edit to http://drupal.org/node/254940
page-user-%.tpl.php --> page--user--%.tpl.php
page-user-edit.tpl.php --> page--user--edit.tpl.php

The new suggestion wildcard for integer arguments accepts % suggestions page--user--%.tpl.php. Suggestions which have additional arguments like page--user--edit.tpl.php remain the same; this simply differentiates the suggestions with and without integer args.