I am trying to organize my theme folder, which has node theming overrides for dozens of views. Basically I have two different styles and I want them all to look the same, more or less.
Is there a way in template.php that I can do this? And what is the best way?
I tried this code in my theme's hook_preprocess_node function:
switch($vars['view']->name) {
case 'taxonomy_term' :
switch($vars['view']->current_display) {
case 'page' :
array_push($vars['template_files'], 'list-view');
default :
break;
}
break;
default :
break;
}
And when I look in theme developer, I can see the list-view.tpl.php file there, but its not actually using that file from my theme directory. What am I missing?
As you can see in theme() Drupal will only actually use a template if it exists according to drupal_discover_template().
You should try to figure out if that is the case.
place some debug code in the theme() function in includes/theme.inc to see what drupal_discover_template() returns for vairious template calls.
Can it find it?
If not:
place some debug code in drupal_discover_template() to find out where Drupal thinks it no longer is a template.
My gut-feeling says that it is due to subdirectories where the template files reside, but which you have not added to the template_files variable: views/lists/some_list.tpl.php is not the same as some_list.tpl.php.
You need to rebuild the cache for the tpl.php file to be picked up.
Related
I am building a custom module with Drupal 8. One of the requirements of the module is that it sets up a javascript file based on the configuration settings, which the user of the module sets up in module configuration.
The javascript which needs to be added to the page depends on the configuration settings. Hence I can not add it using Libraries as mentioned in this article: Adding assets to Drupal module.
I first implemented it using a block. I use Twig templates to pass the configuration variables in PHP to the twig file, and in the twig file, I have a tag to add the javascript based on the config variables. Refer Using twig templates.
The problem with this approach is that user needs to add the block on the page, and there is no UI facing element on that block. I also find it very messy.
Is there a cleaner way to add my javascript using hook and pass variables to it? I looked around and found hook_install and hook_page_attachments. So I can add Javascript, but don't know how I can pass any php variables to it.
I am new to Drupal development. Any help with this is really appreciated.
TL;DR I need to find a way to add Javascript using Drupal hook and pass some PHP variables to it.
Use in hook_page_attachments:
$attachments['#attached']['drupalSettings']['myvar'] = $myVariable;
Then in your js (I assume you already know how to attach js library):
(function ($, Drupal, drupalSettings) {
Drupal.behaviors.my_custom_behavior = {
attach: function (context, settings) {
var strings = drupalSettings.myvar;
...
}
}
})(jQuery, Drupal, drupalSettings);
See nice Acquia tutorial for more examples.
Here is my current issue : I am using a custom child theme (from Parabola, Cryout Creations, last version), but it seems that the editor-style.css file is not up-to-date. Rather than rewriting everything, I would like it to contain every css used on the front-end, so TinyMCE looks as close as the published page/article (this is important).
In order to do that, I have created a new editor-style.css file in my child theme, so it overrides the not-up-to-date file. So far, it includes the style.css file from my theme, but it lacks a lot of CSS from WordPress Core : the ones written on line 60 on the index file : http://nouveau.domaineloupia.com.
So, how to add this “core CSS” to my editor-style.css file ? And would it be the best way to do this ? I have seen many stuff talking about the add_editor_style function, but I do not know if I could use it to do what I want nor how.
Thanks for reading so far, and thank again in advance for any help you could provide !
You could just use #import url("YOURCORECSS.css"); in the top of your `editor-style.css' file?
But that tends to slow down your pages.
I have a small problem with Shopware aplication. My point is, I create a new Theme which works perfectly, I can change any information at webpage using shopware backend profile, but when i copy the less files to my new repository folder, I cannot compile new theme. It stucks.
From the beginning,
Creating a theme using parent Responsive, all works perfect, theme compile.
Changing information on page, work perfect, theme compile.
Copy less files from Responsive/_public/less to newrepository/frontend/_public/less etc and it stucks.
Right now i dont have any idea how I am suppose to deal with it.
Any ideas ?
When a theme in shopware doesn't compile there is most probably something wrong with your less files. Have you copied all less files?
The path you mentioned is not correct.
syntax error in less files?
Did you copy the file Responsive/frontend/_public/src/less/all.less without copying the files that are imported in the all.less? Same applies for other files in this directory.
Whatever it is that is wrong with your less files. You shouldn't need to copy them from the parent theme. If you want to change something, just create your own files.
Say you want to have the background white. Create a file YOUR_THEME/frontend/_public/src/less/_modules/body.less with the content:
body {
background: #fff;
}
Then you are also going to need a file YOUR_THEME/frontend/_public/src/less/all.less with the content:
#import "_modules/body";
No need to copy or modify the original files.
Create a .css file here:
Responsive/frontend/_public/src/css/style.css
After that you should include the file in your Theme.php file like this:
protected $css = array('src/css/style.css');
under this function:
public function createConfig(Form\Container\TabContainer $container)
{
}
It worked for me. I have no idea how to include less files in a theme, they are usually added in a plugin by creating an event. I hope this helps.
Also Responsive Theme is default theme in Shopware. You should extend it and work on the newly created theme.
I guess it is obviously but are you following the Shopware strukture?
all.less (#import "modules";)
--_modules (#import "_modules/your";)
---your.less
?
Please don't copy all Less Files from the responsive theme. There are some mixins for the grid that stucks if you compile it twice, which is exactly the case if you copy all the files.
This is a simple concept question... If I have a wordpress plugin and I want to write some functions for my own IN ADDITION to what they have already where would I put them in the wordpress file structure?
I cant put them in the original core.php files/directory because they will get wiped out when the plugins are updated right?
#NomikOS - Yeah Sure .. I have a wordpress plugin called BP-Phototag- pretty much an album..Its located in the wp-content/plugins folder. I want to add my own functions...for a specific template in my themes folder. DO i put the functions in the bpa.core.php file in the wp-conten/plugins folder or do I make a new php file that can inherit bpa.core.php functions(which I dont know how to do) and stick them in my template specific folder under wp-content/themes/mytheme folder. Im really not sure how to extend and override it...
If the plugin is class based, you can extend it to override/add methods. You can include the file containing your code inside plugin's directory if you want (it will not deleted after an upgrade) or directly inside plugins dir.
EDIT 1
Sorry, I didn't saw your last comment. Well, my friend, it's time to learn OOP PHP5. I recommend you PHP 5 objects, patterns, and practice. It's for PHP serious coders.
Basically you do
class leon_my_class extends BP_Phototag_class {
function __construct()
{
parent::__construct();
// my code
}
// overriding protected/public method
function BP_Phototag_method()
{
// this code will replace original code
}
// adding method
function my_own_method()
{
}
}
Is there a place where I can place override theme files other than a theme's folder? For example, if I wanted to override the appearance of a view's row in the same style for more than one theme without having to use more than one file.
If there isn't a generic way to do this (for any theme file), is there a way to do it for a view's theme files?
In your module, you can use hook_theme to declare a theme function or template for your view's row. This way, your single template will be used by all your themes without any special code in them. See the Theming your views in your module section in the Views's API Advanced Help page.
You could include an include_once type statement in your tpl.php file and just import the code from where ever. This way you have any number of files that refer to one.
It is not recommended though since if you move your theme folder or rename anything this can be harder. Also if you put your theme in another site you need to keep track of all of these off-theme hacks.
I think views seeks tpls inside of the theme folder. It's be nice to have something like that though.