Provide pattern and suggestion theme templates from a module

in

Pattern and suggestion theme templates normally can only reside in the theme directory. This can make the theme folder filled with many many templates that can sprawl over time. This makes sharing templates between active themes impossible, switching theme or upgrading theme very hard. It would be much better to house these templates inside a module or inside some site/files folder. This makes module fully able to provide override theme templates out of the box. No copying files to theme necessary.

Here is the code to make this happen, which basically makes a module behave like a theme as far as theme template override goes:

function hddigitalworks_theme_registry_alter(&$registry) {
  // point to where the templates are. This can be anywhere
  // like inside the site files directory
  $path = drupal_get_path('module', 'hddigitalworks') . '/templates';

  // pretend we are a theme, go discover pattern templates in our module directory
  _theme_process_registry($registry, 'phptemplate', 'theme_engine', 'hddigitalworks', $path);
}

The _theme_process_registry() auto-discover any templates and add them to the theme registry. It is a core internal function (the under-score in front). Using it here is probably not very kosher. Unlikely to change within one major drupal version, I hope (famous last word).

The code handles both suggestion templates and pattern templates. Views and Webforms make use of pattern templates. Suggestion templates are described in template suggestions? But there is not much information about pattern template are available. The hook_theme() api doc describes the 'pattern' key but doesn't go in any details. The views module is a very good place to learn how to create and use pattern template hooks. Both kinds of templates serve the same purpose: enable template override of a given theme hook. The reason to use pattern template is performance. Pattern is matched during theme register build and they turn into new theme hooks base on the file pattern in the original hook's "pattern" key. At runtime, the theme() call is invoked with an array of hook names and the corresponding hook info is directly found out of the theme registry. Whereas template suggestion must be searched subtheme(s) to base theme, etc, which can take time because it involve file system access. So for high performance theme hook needs override, pattern template is better.

I wanted to have a unique

GE PHP900SMSS's 的頭像

I wanted to have a unique simple html flash page posted while working on the site.
I posted the above function into my themes/garland/template.php the redirect works well.
however, i cannot access the admin page to work on the site..

Should the code be added to

ByFiles's 的頭像

Should the code be added to the current theme's template or the template of the other theme one wants to use for the content type? Where do you pick the theme once you add the code to the template? Also does the devel_theme module need to be enabled to use this? Thank you for any help in advance.

Joshua.

This was a fantastic post.

dual saw's 的頭像

This was a fantastic post. Really loved reading your weblog post. The information was very informative and helpful.

I am happy to find your

double cut saw's 的頭像

I am happy to find your distinguished way of writing the post. Now you make it easy for me to understand and implement the concept. Thank you for the post.

Thanks, some great data here

spinal cord injury attorneys harrisburg's 的頭像

Thanks, some great data here keep up the good work. I actually allow for a more creative comment as I'm a bit out of my depth but I will be checking back here for further updates.

The variation of templates is

logo maker's 的頭像

The variation of templates is important to me. Being able to switch from one to another seamlessly can save valuable time. How reliable are template suggestions, and do they follow protocol when meeting conditions specified? Even if they do, it still seems a bit rigid to me, in that they only arrive at point X if conditions a-z are apparent. If the code above can override specific theme hooks, then this should create a more flexible environment when searching for and switching between templates.

Superb coding shared at this

jeffersonlobo's 的頭像

Superb coding shared at this site and it really proved helpful to me to override theme directory.thanks fo rthe view.

seward shuttle

Hey

GPS Intelligence's 的頭像

I was very happy that I discovered this site. I needed to thank you for this great information!! I absolutely loved every bit of it and I have bookmarked your blog to check out the new stuff you post down the road.

This code provieds high

anchorage whittier's 的頭像

This code provieds high performance theme hook and it needs override, pattern template is better.thanks for the view.

Hello how to //point where

gardening blog's 的頭像

Hello how to //point where the templates are,in this coding,as I am not able to point it??

A great informative blog.Keep

Free Cell Phone Spy's 的頭像

A great informative blog.Keep posting articles like this.You have a great knowledge on subject.Thanks for sharing such an article where education of people matters the most.Your way of expressing articles through words is excellent.The way of expressing things is best and informative.

A great informative blog.Keep

Free Cell Phone Spy's 的頭像

A great informative blog.Keep posting articles like this.You have a great knowledge on subject.Thanks for sharing such an article where education of people matters the most.Your way of expressing articles through words is excellent.The way of expressing things is best and informative.

Very Helpful

4G LTE Phones's 的頭像

This was actually very helpful. It was interesting to me that the pattern was matched during theme register build. Other guides I had read had not mentioned this. Thanks again!

The views module is a very

Ugg outlet's 的頭像

The views module is a very good place to learn how to create and use pattern template hooks.

nice post

christmas cards's 的頭像
This is an excellent post, I was looking for this knowledge. Just so you know I found your web site when I was searching for blogs like mine, so please check out my site sometime and leave me a comment to let me know what you think.

nice

Dried Fruits's 的頭像

Even if they do, it still seems a bit rigid to me, in that they only arrive at point X if conditions a-z are apparent.

Dried Fruits

great job

10k training plan for beginners's 的頭像

it's really awesome post like it

marvelous source of info...

Phone Lookup's 的頭像

I visited this page first time and found it Very Good Job of acknowledgment and a marvelous source of info.........Thanks Admin!

marvelous source of info...

Phone Lookup's 的頭像

I visited this page first time and found it Very Good Job of acknowledgment and a marvelous source of info.........Thanks Admin!

Hi I am using the same

frases bonitas's 的頭像

Hi I am using the same procedure in template.php and creating new node--contetype.tpl.php . but i am not getting the content to be in new template . please help me ASAP .thanks in advance

like

maquinas de coser's 的頭像

Even if they do, it still seems a bit rigid to me, in that they only arrive at point X if conditions a-z are apparent.

great job

10k training plan for beginners's 的頭像

it's really good post like it
10k training plan for beginners

great blog

10k training plan for beginners's 的頭像

it's really awesome post i really like it your Blog

great job

10k training plan for beginners's 的頭像

it's really good post

Fatastic Post

cozinhas planejadas's 的頭像

Hi I am using the same procedure in template.php and creating new node--contetype.tpl.php . but i am not getting the content to be in new template
cozinhas planejadas

Great post

cozinhas planejadas's 的頭像

It's really awesome post Like it......
cozinhas planejadas

Great post

cozinhas planejadas's 的頭像

Hi I am using the same procedure in template.php and creating new node--contetype.tpl.php . but i am not getting the content to be in new template

This is a interesting line of

arginina's 的頭像

This is a interesting line of content, very good article.
Thanks for sharing this post, nice way of bring this theme templates subject to discussion.
Keep up the excellent work !

template

does the nono really work's 的頭像

That is probably one of the greatest posts you'll find in the web telling you every little thing in more detail concerning the issue. You could be spending your energy and time to express your current views and also thoughts with plenty of viewers nowadays.

Hi

Mensagens Para Celular's 的頭像

Hi I am application the aforementioned action in template.php and creating new node--contetype.tpl.php . but i am not accepting the agreeable to be in new arrangement . amuse advice me ASAP .thanks in advance

That is probably one of the

london web design's 的頭像

That is probably one of the greatest posts you'll find in the web telling you every little thing in more detail concerning the issue. You could be spending your energy and time to express your current views and also thoughts with plenty of viewers nowadays.

Im no expert, but I believe

special education Teacher salary's 的頭像

Im no expert, but I believe you just made an excellent point. You certainly fully understand what youre speaking about, and I can truly get behind that. Thanks for staying so upfront and so sincere.

Favorite post having such an

purchase facebook likes's 的頭像

Favorite post having such an fantastic and useful informative content. describing good blogging concepts as well as basics that are very much useful in skilled content writing as well

Wonderful article, thanks for

Traffic school online's 的頭像

Wonderful article, thanks for putting this together! This is obviously one great post. Thanks for the valuable information and insights you have so provided here.

This is a great inspiring

photography grants 2012's 的頭像

This is a great inspiring article.I am pretty much pleased with your good work.You put really very helpful information. Keep it up. Keep blogging. Looking to reading your next post.

發表新回應

這個欄位的內容會保密,不會公開顯示。

Navigation

使用者登入