I have a template file for a entity type inside my theme's folder.
How can I use the same template file in the admin area which uses the Seven theme?
Thanks. M
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.
Sign up to join this communitySince it's always bad practice to hack core, you would have to do it with a custom module. This would be done with either template suggestion overrides or with template suggestions in a preprocess hook such as template_preprocess_node or template_preprocess_page.
Unfortunately this is not enough when you place the template file (tpl) anywhere but the theme's templates/
folder. Your custom module's template folder is not known by default so you will have to notify Drupal about. To do this, you will need to use hook_theme_registry_alter. Here below is an example from one of my projects in Drupal 7 (and it's live and works).
/**
* Implements hook_theme_registry_alter()
*/
function CUSTOM_MODULE_theme_registry_alter(&$theme_registry) {
// The Templates path in your custom module you want to add...
$mod_path = drupal_get_path('module', 'CUSTOM_MODULE') . '/includes/templates';
// ... or the Templates path in your custom theme.
// If you use your already existing custom theme's path, make sure you remember that this
// function exists when you alter or disable the custom theme.
$mod_path = drupal_get_path('theme', 'CUSTOM_THEME') . '/templates';
$theme_registry_copy = $theme_registry;
_theme_process_registry($theme_registry_copy, 'phptemplate', 'theme_engine', 'pow', $mod_path);
$theme_registry += array_diff_key($theme_registry_copy, $theme_registry);
$hooks = array('node');
foreach ($hooks as $h) {
_CUSTOM_MODULE_insert_after_first_element($theme_registry[$h]['theme paths'], $mod_path);
}
}
/**
* Helper function for re-ordering arrays (needed by theme_registry_alter)
*/
function _CUSTOM_MODULE_insert_after_first_element(&$a, $element) {
if(is_array($a)) {
$first_element = array_shift($a);
array_unshift($a, $first_element, $element);
}
}
I've seen people advocate (or at least suggest) the use of theme_hook()
instead, but I actually find the theme registry way a lot easier to handle. Especially when you add more templates at a later stage during the development process.
pow
as the theme name works (it doesn't seem to work with any other theme name). Do you have any idea?
$mod_path
declaration for a theme. It should be noted that if you use the theme path and that theme later is moved/deleted/disabled, things could go bad. Regarding pow
. I have actually never reflected over why I use that. It's probably because the first example I saw with it used that. Anyways, I can't seem to get it to not work with anything else. I've tried with all standard theme names, as well as totally random ones and also an empty string. It always picks out my custom template file. I'll continue digging.
You have a choice.
Goto host.com/admin/appearance
Scroll down to find ADMINISTRATION THEME
And uncheck the check box "Use the administration theme when editing or creating content"
template.php
file. You'd have to add a new template path so Drupal knows about it since it would only check in the admin theme's template folder. The reason why I don't write this as an answer is because I don't have the time to be more elaborate and give examples.