Custom Template Suggestions allows you to enter names of custom node.tpl.php and page.tpl.php files that you would like to be used for that specific node. For example, if I have both an English and French version of a node, I could use the suggestion fields to make sure that both nodes use the same template files.

The module essentially utilizes template_preprocess_node() and template_preprocess_page() to add your custom templates into the end of the theme_hook_suggestions array. If you add, update, or delete a template, it will also clear the page cache for you, otherwise the page cache will be left intact.

I wasn't able to find any modules that provided similar functionality to this. You can produce the same results by adding fields to your content type and using your theme's template.php, but I wanted to be able to provide a more streamlined solution.

Project page: https://www.drupal.org/sandbox/s-robertson/2341113

Clone command:
git clone --branch 7.x-1.x http://git.drupal.org/sandbox/s-robertson/2341113.git

Comments

PA robot’s picture

Status: Needs review » Needs work

There are some errors reported by automated review tools, did you already check them? See http://pareview.sh/pareview/httpgitdrupalorgsandboxs-robertson2341113git

We are currently quite busy with all the project applications and we prefer projects with a review bonus. Please help reviewing and put yourself on the high priority list, then we will take a look at your project right away :-)

Also, you should get your friends, colleagues or other community members involved to review this application. Let them go through the review checklist and post a comment that sets this issue to "needs work" (they found some problems with the project) or "reviewed & tested by the community" (they found no major flaws).

I'm a robot and this is an automated message from Project Applications Scraper.

Scott Robertson’s picture

Status: Needs work » Needs review

Errors/warnings from the automated review have been fixed.

karan_mudi’s picture

Don't have cloning permission to any other user.

devd’s picture

Hi Robertson,

Please replace the added clone command by the following:

git clone --branch 7.x-1.x http://git.drupal.org/sandbox/s-robertson/2341113.git

So reviewer can download and review your your project.
You are feel free to take my help on my skype ID: devendra.icreon or dev.firoza.

devd’s picture

Category: Task » Bug report
Priority: Normal » Major
Status: Needs review » Needs work
Issue tags: +array warnings, +Framework InitiativePerformance
StatusFileSize
new31.36 KB
new1.41 KB

Hi Robertson,

Please fix the following error.

Erorr 1: Notice: Undefined property: stdClass::$nid in _cts_get_custom_templates() (line 201 of /var/www/7drupal-1/sites/all/modules/custom/2341113/cts.module).
Solution:

To reproduce:
This error generate when someone create the node.

Solution:
Replace $custom_templates = _cts_get_custom_templates($form['#node']); by

if (isset($form['#node']->nid) && $form['#node']->nid) {
$custom_templates = _cts_get_custom_templates($form['#node']);
}

Error 2:
Replace
$result = db_query('SELECT * FROM {cts} WHERE nid = :nid', array(':nid' => $node->nid));

By
$result = db_query('SELECT type, template FROM {cts} WHERE nid = :nid', array(':nid' => $node->nid));

How to apply attached pacth

1- Get the clone using the git.
2- modules/contrib$ cd 2341113
3- Paste the patch file inside your project folder 2341113.
4- modules/contrib/2341113$ git apply -v patch_file_name

Scott Robertson’s picture

Issue summary: View changes
Scott Robertson’s picture

Hi Devendra,

Thanks for taking a look at the module, it's much appreciated. I've applied your patch and pushed the changes up. I also fixed the clone command.

Best,
Scott

Scott Robertson’s picture

Status: Needs work » Needs review
devd’s picture

Hi Scott,

I have a question in my mind. By your module we can create the Template Page for each node.
If i create the different Template Page for more than one node then which template will be called.?

Scott Robertson’s picture

Hi Devendra,

I'm not sure if I understand your question, would you mind clarifying? I can think of the following scenarios when dealing with multiple templates and/or nodes:

1) If you specify different template suggestions for each node, there will be no conflict as each node would be using different template files.

2) If you specify the same template suggestions for more than one node, all of those nodes will just use the same template files.

3) If a node is already using a template file from Drupal's default template suggestions (e.g. page--node--1.tpl.php), the module would make the custom-specified template higher priority in the suggestions, overriding the previous one.

Of course this all assumes that you actually create page--custom--[name].tpl.php or node--custom--[name].tpl.php files in your theme folder, otherwise nothing would change aside from that Drupal would try and look for the custom templates.

Best,
Scott

robin.ingelbrecht’s picture

StatusFileSize
new46.54 KB

@s-robertson,

I installed your module, created a sub-theme of omega and created a node with custom template "test".
Then I made a file in my theme folder called "node--custom--test.tpl.php"
This is what my template suggestions look like:

Suggestions

Your module seems to work fine! No security issues on first sight, clean code.

My only suggestion: maybe use db_select instead of db_query.
Good job!

f0ns’s picture

Checked out this module, everything seems to work just fine.

I agree with @robin.ingelbrecht concerning the use of db_select instead of db_query.

Scott Robertson’s picture

Hi robin.ingelbrecht and f0ns,

Thanks for taking some time to look at the module; I've switched from db_query to db_select as you suggested.

Best,
Scott

Bartuc’s picture

I ran through the code and couldn't find any issues! Looks good.

I don't think you should switch db_query to db_select. There is no reason to do this as db_select is much slower. The only advantage it gives you is the ability to hack into the query. If you don't need this ability then you don't need to use db_select.

Refer to this post: https://www.drupal.org/node/1881146#comment-6907576

While there are valid arguments each way, I can't find a reason to use db_select over db_query when creating a simple database call. Drupal 8 seems to fix this age old problem though.

Scott Robertson’s picture

Hi Bartuc,

Thanks for taking a look at the module. After doing some more reading, I agree that going back to db_query is the right call. Considering the simplicity of the query, the performance differences, and the fact that the query is being called whenever a node is loaded, I don't see any reason why I shouldn't use db_query instead. I've gone ahead and reverted the commit.

Scott

b_sharpe’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me

wnh’s picture

Using this in production and it works great!

stborchert’s picture

Category: Bug report » Task
Priority: Major » Normal
Status: Reviewed & tested by the community » Fixed
Issue tags: -array warnings, -Framework InitiativePerformance

Thanks for your contribution, Scott!

I updated your account so you can promote this to a full project and also create new projects as either a sandbox or a "full" project.

Here are some recommended readings to help with excellent maintainership:

You can find lots more contributors chatting on IRC in #drupal-contribute. So, come hang out and stay involved!

Thanks, also, for your patience with the review process. Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.

Thanks to the dedicated reviewer(s) as well.

Status: Fixed » Closed (fixed)

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