What is the difference between these 2 functions that can but put in template.php for Drupal?
function THEME_preprocess_image(&$variables) {
// something
}
function THEME_image($variables) {
// something
}
function theme_image renders the HTML output for a renderable array.
THEME_preprocess_image
I do believe, that the right name for that is template_preprocess_HOOK, it is called inside of theme() before theme function eg. THEME_image
Please consider the use case here:
// In custom.module
$variables = array(
'path' => 'path/to/img.jpg',
'alt' => 'Test alt',
'title' => 'Test title',
'width' => '50%',
'height' => '50%',
'attributes' => array('class' => 'some-img', 'id' => 'my-img'),
);
$img = theme('image', $variables);
If you want to change some attributes of an image, you do the following:
function mytheme_preprocess_image($vars) {
// Do the changes, before it's rendered.
}
Related
I'm trying to add a tab to my Publish entry form, I have the following code (pruned for simplicity), but it's not working:
in tab.my_module.php:
public function display($channel_id, $entry_id = '')
{
$settings = array();
$settings = array(
'custom_field' => array(
'field_id' => 'custom_field',
'field_label' => 'custom_field',
'field_type' => 'text'
)
);
return $settings;
}
in upd.my_module.php:
public function install() {
ee()->layout->add_layout_tabs($this->tabs(), 'my_module');
}
public function tabs()
{
$tabs['my_module'] = array(
'custom_field'=> array(
'visible' => 'true',
'collapse' => 'false',
'htmlbuttons' => 'true',
'width' => '100%'
),
);
return $tabs;
}
But hte tab doesnt appear after i reinstall the module, what am I missing?
The problem was caused by having style information in the lang file!
The new tab was actually being included on the Publish and Edit pages but the style in the Tab title was somehow causing the new tab to be hidden.
$lang = array(
'module_name' => 'My Module',
'module_description' => 'Brief description ',
'save_btn' => 'Save',
'save_btn_clicked' => 'Clicked',
'module_name' => '<style color="green">My Module</style>',
);
I tried to pass a variable from a custom module to a tpl file.
In my custom module (named example)
1. I created a route with an argument via hook_menu :
function example_menu() {
$items['example/fancybox-photos/%'] = array(
'page callback' => 'example_display_fancybox_photos',
'page arguments' => array(2),
'type' => MENU_CALLBACK,
'access arguments' => array('access content'),
);
return $items;
}
2. I created my page callback function :
function example_display_fancybox_photos($nid) {
$nodePhoto = node_load($nid);
$field_photo = field_get_items('node', $nodePhoto, 'field_photo');
$photo = [
"field_photo" => $field_photo[0]['uri'],
....
];
return theme('example_fancybox_photos', array('infosPhoto' => $photos));
}
3 . I created a hook_theme
function example_theme() {
$themes = array();
$themes['example_fancybox_photos'] = array(
'template' => 'templates/example-fancybox-photos',
'variables' => array('infosPhoto' => NULL),
);
return $themes;
}
4 . I finally created a tpl named "example-fancybox-photos.tpl.php" in templates folder (in theme folder)
<pre><?php print var_dump($infosPhoto); ?></pre>
The result is NULL
I did some researchs but i dont understand why the variable is still NULL.
thanks for your help !
I finally managed to get the variable from the module to the tpl !
1. I created a route with an argument via hook_menu :
function example_menu() {
$items['example/fancybox-photos/%'] = array(
'page callback' => 'example_display_fancybox_photos',
'page arguments' => array(2),
'type' => MENU_CALLBACK,
'access arguments' => array('access content'),
);
return $items;
}
2. I created my page callback function :
function example_display_fancybox_photos($nid) {
$nodePhoto = node_load($nid);
$field_photo = field_get_items('node', $nodePhoto, 'field_photo');
$photos = [
"field_photo" => $field_photo[0]['uri'],
....
];
return theme('example_fancybox_photos', array('infosPhoto' => $photos));
}
3 . I created a hook_theme
function example_theme() {
$themes = array();
$themes['example_fancybox_photos'] = array(
'template' => 'templates/example_fancybox_photos',
'variables' => array('infosPhoto' => NULL),
);
return $themes;
}
4 . I finally created a tpl named "example_fancybox_photos.tpl.php" in templates folder (in MODULE (example) folder)
The problems were that:
- the tpl was not named in the same way and with dashes instead of underscore
- the tpl was in the template folder of the theme and not of the module
You have passed $photos but you have array as $photo. try to change that
Hope the below code helps you.
function example_menu(){
$items['example/fancybox-photos/%'] = array(
'page callback' => 'example_display_fancybox_photos',
'page arguments' => array(2),
'type' => MENU_CALLBACK,
'access arguments' => array('access content'),
);
return $items;
}
function example_display_fancybox_photos($nid){
$photos = 'value from example module!';
return theme('example_fancybox_photos',array('photos' => $photos));
}
function example_theme() {
$path = drupal_get_path('module', 'example');
return array(
'example_fancybox_photos' => array(
'variables' => array('photos' => null),
'template' => 'example_fancybox_photos',
'path' => $path,
),
);
}
Place your tpl file example_fancybox_photos.tpl.php in your module directory and inside it use the below code.
<?php print $photos; ?>
or
function example_theme() {
return array(
'example_fancybox_photos' => array(
'variables' => array('photos' => null),
'template' => 'example_fancybox_photos',
),
);
}
Place your tpl file example_fancybox_photos.tpl.php in your theme directory and inside it place the below code
<?php print $photos; ?>
I am developing a custom module in Prestashop. In that module I want to show my custom saved values like the table order. So basically the table should have header part and in that header part there would input fields to search the record for the corresponding data header. So the module custom page header should show like this reference image
So can some one tell me how to do this in a custom module? Any help and suggestions will be really appreciable. Thanks
You need some effort to make it all work but for displaying table header, and I do hope you are using HelperList class,
$helper->simple_header = false;
Check official documentation.
Assuming you know how to make a module, all you need is this (bear in mind it is an example and you'll have to replace bits and pieces here and there).
file /modules/mymodule/controllers/admin/AdminRulesController.php
class AdminRulesController extends ModuleAdminController
{
public function __construct()
{
$this->module = 'mymodule';
$this->table = 'rules'; //table queried for the list
$this->className = 'Rules';//class of the list items
$this->lang = false;
$this->bootstrap = true;
$this->context = Context::getContext();
$this->fields_list = array(
'id_rule' => array(
'title' => $this->l('ID'),
'align' => 'center',
'class' => 'fixed-width-xs',
'search' => false, //in case you want certain fields to not be searchable/sortable
'orderby' => false,
),
'name' => array(
'title' => $this->l('Rule name'),
'align' => 'center',
),
'is_active' => array(
'title' => $this->l('Active'),
'align' => 'center',
'type' => 'bool',
'active' => 'status',
),
'comment' => array(
'title' => $this->l('Comment'),
'align' => 'center',
'callback' => 'displayOrderLink' //will allow you to display the value in a custom way using a controller callback (see lower)
)
);
parent::__construct();
}
public function renderList()
{
$this->addRowAction('edit');
$this->addRowAction('delete');
return parent::renderList();
}
public function displayOrderLink($comment)
{
switch($comment)
{
case 'value1':
return '<span style="color:red">mytext</span>';
case 'value2':
return '<strong>mytext</strong>';
default:
return 'defaultValue';
}
}
}
Is it possible to update a highcharts chart using the chart.series[i].setData method if the chart has been created by the Yii extension? I have used highcharts before without Yii extension and able to reference my variables once I set the chart up via declared variable var chart = .... I would just like to to able to call the setData methods for a Yii-created highcharts...this is current code for creating chart:
$this->Widget('ext.highcharts.HighchartsWidget', array(
'id' => 'shop_pie',
'options' => array(
'chart' => array(
'backgroundColor' => '#efefef'
),
'colors' => $colors,
'title' => array('text' => 'Shop'),
'plotOptions' => array(
'pie' => array(
'showInLegend' => 'true',
'dataLabels' => array(
'formatter' => 'js:function(){return this.point.y}',
'distance' => -10,
'color' => '#000'
),
),
'series' => $results['series'],
)
));
My ajax call to update the chart:
"$('#city_filter').on('change',function(e) {
$.ajax({
url: ". $quotedUrl . ",
data: { 'cities': e.val },
success: function(data) {
$('#name_span').text(data[0]);
//chart.series[0].setData(data[1]); // THIS IS WHERE I NEED TO BE ABLE TO REFERENCE THE CHART
}
});
});",
Many thanks in advance.
Andy
"$('#city_filter').on('change',function(e) {
$.ajax({
url: ". $quotedUrl . ",
data: { 'cities': e.val },
success: function(data) {
$('#name_span').text(data[0]);
var chart = $('#shop_pie').highcharts();
chart.series[0].setData(data[1]); // THIS IS WHERE I NEED TO BE ABLE TO REFERENCE THE CHART
}
});
});",
referring to
http://api.highcharts.com/highcharts#Series.setData
and example from that article
http://jsfiddle.net/gh/get/jquery/1.7.2/highslide-software/highcharts.com/tree/master/samples/highcharts/members/series-setdata/
In my view I have this code:
echo $form->select2Row($model, 'Zustelladresse', array(
'asDropDownList' => false,
'options' => array(
'placeholder' => "Zustelladresse",
'width' => '100%',
'closeOnSelect' => true,
'minimumInputLength'=>1,
'initSelection' => "js:function (element, callback) {
var selected_data = new Object;
selected_data.id = '123';
selected_data.text = 'Test';
callback(selected_data);
}",
'ajax' => array(
'url' => Yii::app()->createUrl('address/zustelladresse'),
'dataType' => 'json',
'data' => 'js:function(term,page) { if(term && term.length){ return { zustelladresse: term };} }',
'results' => 'js:function(data,page) { return {results: data}; }',
),
)));
Created html:
Why is created only label and hidden input?
YiiBooster widgets are quite tricky to debug, if anything is wrong they just don't show. If you still need the answer, I successfully displayed a select2 widget with this code:
$form->select2Row($model, 'attribute_name', array(
'data' => array('1'=>'value1,'2'=>'value2'),
'htmlOptions'=>array(
'style' => 'width:600px',
'multiple' => true,
),
'options'=>array('placeholder'=>'Please make a selection'),
));
I'd suggest you to start from this code and add up your options one by one, and see if anything breaks.