I tried using hook_custom_theme to change the theme for the node add page for a specific content type, like this, without success:
function mymodule_custom_theme() {
if (current_path() == 'node/add/mytype')
return 'anothertheme';
}
I know the function is running, and I know the comparison is returning TRUE. Why is it not working?
I think you are not writing the theme name correctly.
But there is a module which could do this work for you: https://drupal.org/project/themekey
Regards.
1) Do you use the correct machine name for the theme?
2) Are you sure that there are not other modules to override this later?
3) Is the page cached? If so this may not work properly.
Same question and discussion here: https://drupal.stackexchange.com/questions/812/how-do-i-change-a-theme-based-on-the-url
Useful modules:Page Theme, Context, ThemeKey.
Related
I am in the process of adding a copyright line to the footer of a website that I have been working on and I cannot find the best way to get the current dynamically into the footer so I never have to set it again. I have tried multiple things, including a global setting that can be accessed from anywhere, but nothing has worked.
Any feedback would be appreciated. Thanks.
Write an ApostropheCMS nunjucks helper function. See those docs for the general issues around this. Your specific function could look like:
self.addHelpers({
thisYear: function() {
return new Date().getFullYear();
}
});
If you put that in construct of a module of your own, let's say it's called helpers, then you can call it in Nunjucks as {{ apos.helpers.thisYear() }}.
These are very handy, just remember they cannot do any async work.
When using a custom front-end theme, the preview button for my content stops working. It just redirects to the content overview page.
Am I missing something in my theme that allows me to use the 'preview' function?
You most likely have the ?destination=admin/content in your URL. This is a core bug. The current discussion can be read at:
https://www.drupal.org/node/2325463
Jason Ruyle's answer is correct, I had the same problem and solved it by adding this code to my module:
use Drupal\Core\Entity\EntityInterface;
function my_module_entity_operation_alter(array &$operations, EntityInterface $entity) {
if (isset($operations['edit']['query'])) {
unset($operations['edit']['query']['destination']);
}
return $operations;
}
The code could also be improved to target the right entities, if needed.
Drupal 7,
Views,
Bootstrap theme sub theme in use
I have a views-view-table.tpl.php file in my sub theme and I am trying to preprocess some of the variables sent to this tpl. I created a function bootstrap_preprocess_views_view(&$vars) in my template.php and it is not getting called when I visit one of my views pages. Why would this be? Other preprocess functions are getting called from the same template file. I have tried flushing the cache.
function bootstrap_preprocess_views_view(&$vars) {
dsm($vars);
dsm("aaaa");
die;
}
Adam,
I'm assume you've tried all the regular things like clearing your cache, etc before expecting to see the change.
If yes, perhaps this old Drupal issue may be affecting your function: http://drupal.org/node/258089 (since your syntax looks fine).
Do you actually have a corresponding template file in your sub-theme? If you place one in there (even just by copying and pasting the default one from the views module), does it solve your issue?
Let us know!
What is mean by the following code, I found it in the comment module (drupal 6)
return theme('box', $title, drupal_get_form('comment_form', $edit, $title));
I have used this theme function before, but I had defined some themes under hook_theme(). but I didn't see any themes defined as 'box', also I found same theme 'table'
Could you please show some urls where it explains about these things
Thank you very much
With the Drupal theme system you can overwrite theme functions. So if you don't like the markup that theme_box makes, you can make my_theme_box instead and Drupal will use that function instead. The thing is in order for this to work you can't call theme_box directly. If you do that you in your module your theme can't alter the output. Instead you call theme('box', ...) this will tell Drupal that's it's the box theming function you want. It will the find out which function to call based on what's available. So if your theme doesn't have my_theme_box defined theme_box will be used instead.
Have you already read Drupal API Reference? There's an explanation about themes, too.
We've created a custom module for organizing and publishing our newsletter content.
The issue I'm running into now -- and I'm new to theming and Drupal module development, so it could just be a knowledge issue as opposed to a Drupal issue -- is how to get each newsletter themed.
At this point the URL structure of our newsletter will be:
/newsletters/{newsletter-name}/{edition-name}/{issue-date} which means that we can create template files in our theme using filenames like page-newsletters-{newsletter-name}-{edition-name}.tpl.php, which is great. The one issue I'm running into is that all of the content comes through in the $content variable of the theme. I'd like to have it come through as different variables (so that I can, inside the theme, place certain content in certain areas.)
Is there a proper way for doing this?
Edit: To answer some questions: The issue is a node (there are issue, edition and newsletter nodes) and the path is being set using hook_menu with wildcards and a router.
The best answer I could find was to add a check inside of phptemplate_preprocess_page to send the vars back to the module and have them be updated.
Like so:
function phptemplate_preprocess_page(&$vars) {
if (module_exists('test_module')) {
_test_module_injector($vars);
}
}
then in my test_module.module file I created this function:
function _test_module_injector(&$vars) {
$vars[] = call_to_other_functions_to_load_vars();
}
It seemed to work. I wish there was a way to do this without having to touch the theme's template.php file, but otherwise this works well.
If there were better documentation for template preprocess functions, Drupal would be a lot more accessible - as it is, you need to piece together the information from a lot of different explanations. One place to start is here:
http://drupal.org/node/223430
but if you take the time to work through the tutorial below, you'll find you can do most things:
http://11heavens.com/theming-the-contact-form-in-Drupal-6
This is an old post, and the OP's issues seems to have been solved.
However, just for others finding this through Google (or otherwise):
Install the 'Devel' module: http://drupal.org/project/devel
Also the 'Devel Themer' module: http://drupal.org/project/devel_themer
Use Devel Themer to go through the $content variable and find what you need to pull out.
There are a bunch of Devel/Themer docs/tuts out there, but its usage is pretty straightforward. Note, though, that some stuff in there will need to be sanitized before printing in the theme.
The suggestion to show the node as a View and then modifying the view templates sounds pretty crazy, though it'll work.