Goodmorning everyone,
I'm new in Drupal.
I hope don't ask a stupid question.
I'm working with Drupal 7 and I need to edit a custom module for my company developed by another developer.
This is a piece of code where I use "theme" function.
This code is under "sites/all/modules/gestione_attivita_attivita/gestione_attivita_attivita.module"
function gestione_attivita_attivita_block_search_attivita($tipo_ricerca) {
$block['subject'] = "";
$ricerca = gestione_attivita_ricerca_fetchAll($tipo_ricerca);
$block['content'] = theme('ricerca_attivita', array(
'items' => $ricerca,
'tipo_ricerca' => $tipo_ricerca
));
return $block;
}
I know that should exist "ricerca_attivita" hook declared somehere in my files.
I'v been looking for something like "['ricerca_attivita'] = array(" or similar words or sub-words in all my files of my site folder but it doesn't exist.
The only thing I know is that under :"sites/all/themes/customModuleOfmyCompany/templates" there are several tpl files and in particular one called "ricerca_attivita.tpl.php" that work and receives data from theme function but I don't know how this is possible.
I don't know who tell to theme call to go on another folder on another path and use "ricerca_attivita.tpl.php" and not foo.tpl.php for example.
Is there anyone that can help me?
Another thing:
Going under includes/theme.inc and debugginng it I have this printing hook info:
array (
'template' => 'ricerca_attivita',
'path' => 'sites/all/themes/customtheme/templates',
'type' => 'theme_engine',
'theme path' => 'sites/all/themes/customtheme',
'preprocess functions' =>
array (
0 => 'template_preprocess',
1 => 'contextual_preprocess',
),
'process functions' =>
array (
0 => 'template_process',
1 => 'ctools_process',
2 => 'rdf_process',
),
)
but I don't know who is that declare it
I think you should use the developer module for themers https://www.drupal.org/project/devel_themer
And about theming function, did you search for this function inside the themes folder?
Hope that helps.
Related
Hope you all are doing great since last few days i am facing an issue with my WordPress site this is a plugin or theme i am not sure but the file is in theme which throws error of undefined function
because of this error i am not able to open my customize menu from wordpress admin panel
and once i commented the code line where this code exists it start working but widgets does not work properly like if i enable social icons in widgets i wont be able to disable them and save settings here is the code i have commented.
$jobcareer_opt_array = array(
'name' => esc_html__('Title', 'jobcareer'),
'desc' => '',
'hint_text' => '',
'echo' => true,
'field_params' => array(
'std' => esc_attr($jobcareer_widget_title),
/*'id' => cs_allow_special_char($this-
>get_field_id('title')),*/
'classes' => '',
/*'cust_id' => cs_allow_special_char($this-
>get_field_name('title')),*/
/*'cust_name' => cs_allow_special_char($this-
>get_field_name('title')),*/
'return' => true,
'required' => false
),
);
May be there is some version conflict between the theme and Codestar plugin. You can ask your theme's developer for that. Or as a temporary solution just remove cs_allow_special_char function and use its parameter insteaad. For example replace
cs_allow_special_char($this->get_field_name('title'))
with
$this->get_field_name('title')
and it should work then.
I checked the plugin's source, that function doesn't do any critical operation:
function cs_allow_special_char($input = ''){
$output = $input;
return $output;
}
I'm new to theming and I just inherited this code. I need to control where and how to print #output but it's always showing up at the top of the page, above the HTML tags. I looked at the renderable arrays API but I couldn't find anything specific to my problem.
In mytheme.module:
function mytheme_output_block() {
$content = array(
'#theme' => 'my_theme',
'#output' => function_that_returns_JSON();
...
function mytheme_hook_theme() {
return array(
'my_theme' => array(
'vars' => array(
'output' => '',
...
And in my_theme.tpl.php I tried:
<?php print $output; ?>
But it gets ignored. How do I control #output so I can style it?
not super sure but you might need to call the array element directly. Something like:
$theme = mytheme_hook_theme();
echo $theme['output'];
Hope it helps
Which Drupal you use? I assume D7.
Take a look at the documentation of hook_theme: https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_theme/7.x
It's not vars - it's variables
You have missed the template key in your implementation
template: If specified, this theme implementation is a template, and this is the template file without an extension. Do not put .tpl.php on this file; that extension will be added automatically by the default rendering engine (which is PHPTemplate). If 'path', above, is specified, the template should also be in this path.
So what your hook should look like:
function mytheme_hook_theme() {
return array(
'my_theme' => array(
'variables' => array(
'output' => '',
),
'template' => 'my-theme',
...
Remember to clear the caches afterwards.
I am working on a module for Drupal 7. I have a template defined for my content type as node--[content type].tpl.php and placed it in the "themes/[selected theme]/template" directory. I want to keep this template in my "module" directory instead. So when the module is installed I don't have to place the file in to the selected theme folder every time. Is there a way to do this?
Thank you all in advance.
I have less than 10 rep so I cant answer my own question so I'll just modify the question
The following is working for me some how. For both case node edit form view and node view
function [content type]_theme() {
return array(
'[content type]_node_form' => array(
'arguments' => array(
'form' => NULL,
),
'template' => 'node--[content type]--edit',
'render element' => 'form',
),
'node__[content type]' => array (
'variables' => array(),
'template' => 'node--[content type]' ,
'base hook' => 'node',
'path' => "sites/all/modules/[content type]_update/[content type]_update/[content type]/",
),
);
}
I don't completely understand this but it's working.
This link should get you going:
http://www.wdtutorials.com/2011/06/13/drupal-7-how-create-custom-theme#.U6sZ741dXag
You basically want to create a new custom theme.
In addition to the above tutorial, create a new folder 'templates' and add your .tpl files in there instead of the core themes folder.
You can use the below format to specify the template path. Then you can place the tpl file in your module folder.
function MODULENAME_theme() {
return array(
'yourcustom_theme' => array(
'template' => 'mypage', // template file called mypage.tpl.php
'path' => drupal_get_path('module', 'MODULENAME'),
)
);
}
I create a custom module and I want use the complete_url of my future website in the template who used/created by my module.
I tried several ways and searched Google but I don't find a solution.
However this issue seems very simply, that became me crazy x)
So, I must create a variable in my .module and add her when I return the array in the main_socialtag_theme function. Where/How can I do that ?
My .module:
function main_socialtag_block_info(){
$block['main_socialtag']=array(
'info' => t('Main socialtag'),
'cache' => DRUPAL_NO_CACHE,
);
return $block;
}
function main_socialtag_theme(){
return array(
'main_socialtag_block' => array(
'template' => 'theme/main_socialtag_block',
'variables' => array(),
),
);
}
function main_socialtag_block_view($delta=''){
if ($delta == 'main_socialtag'){
return array(
'subject' => '',
'content' => array(
'#theme' => 'main_socialtag_block',
)
);
}
}
Thanks for help, and sorry for my bad english writing !
If you are looking for a way to add, modify and call variables. Check variable_get and variable_set.
To add or modify a variable value:
variable_set("my_variable_name", "value");
To retrieve the value:
$myVal = variable_get("my_variable_name", "");
For hook_theme Implementation, kindly check this question.
I have been searching all day but unable to find any answers - I am sure I am doing it right as worked fine in Drupal 6 and should work fine in Drupal 7.
I want to give a custom theme function to my select element in my form
$form['field_name'] = array(
'#type' => 'select',
'#title' => t('Title Here'),
'#theme' => 'custom_select',
'#options' => $values,
);
I have the theme hook right to declare the new custom theme function but my problem is when using that custom theme function as above I get an empty $variables array which just reads
Array([element] => null)
can anyone see what I may be doing wrong? cleared cache, done everything I can think of - any ideas why Drupal is not passing the element data to the theme function? thanks
well finally figured this one out incase any one else has the problem - make sure you set render element in hook_theme and not variables!
before
function hook_theme(){
return array(
'select_currency' => array(
'variables' => array('element' => null),
'file' => 'module_name.theme.inc',
));
}
after
function hook_theme(){
return array(
'select_currency' => array(
'render element' => 'element',
'file' => 'module_name.theme.inc',
));
}
I was pulling my hair out until I remembered the render element!