Bonjour,
J'ai crée un sous thème may et j'essaie de surchargé des fonctions. J'ai donc crée un fichier template.php dans mon sous-thème.
Mais le fonctionnement des fonctions surchargés est vraiment bizarre.
Dans le thème mayo, j'ai la fonction:
Si je surcharge la fonction dans mon sous-thème station :exemple
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 function mayo_page_alter($page) { // Add meta tag for viewport, for easier responsive theme design. $viewport = array( '#type' => 'html_tag', '#tag' => 'meta', '#attributes' => array( 'name' => 'viewport', 'content' => 'width=device-width, initial-scale=1', ), ); drupal_add_html_head($viewport, "viewport"); }
Je me retrouve dans ma page avec les 2 balises. Cela ne devrait pas le remplacer?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 function station_page_alter($page) { // Add meta tag for viewport, for easier responsive theme design. $viewport = array( '#type' => 'html_tag', '#tag' => 'meta', '#attributes' => array( 'name' => 'viewport2', 'content' => 'width=device-width, initial-scale=1', ), ); drupal_add_html_head($viewport, "viewport2"); }
Et si je fais une modification sur une autre fonction :
Je surcharge
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45 function mayo_build_columns($columns) { $styles = array(); $num_columns = 0; $first = -1; for ($i = 0 ; $i < 4 ; $i++) { if ($columns[$i]) { if ($first == -1) $first = $i; $last = $i; $num_columns++; } } if (!$num_columns) return ''; $out = ''; $out .= '<div class="column-blocks clearfix">'; $column_width = round(100 / $num_columns, 2) . '%'; // calculate percent width of a column for ($i = 0 ; $i < 4 ; $i++) { if ($columns[$i]) { if ($i == $first) { $margin_left_style = 'margin-left: 0px;'; } else { $margin_left_style = 'margin-left: 5px;'; } if ($i == $last) { $margin_right_style = 'margin-right: 0px;'; } else { $margin_right_style = 'margin-right: 5px;'; } $style = $margin_left_style . $margin_right_style; $out .= '<div class="column-block-wrapper" style="width: ' . $column_width . ';">'; $out .= '<div class="column-block" style="' . $style . '">'; $out .= render($columns[$i]); $out .= '</div></div> <!--/.column-block --><!--/.column-block-wrapper-->'; } } $out .= '</div> <!--/.column-blocks-->'; $out .= '<div class="spacer clearfix cfie"></div>'; return $out; }
C'est le code de la fonction du thème et non du sous-thème qui est exécuté.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45 function station_build_columns($columns) { $styles = array(); $num_columns = 0; $first = -1; for ($i = 0 ; $i < 4 ; $i++) { if ($columns[$i]) { if ($first == -1) $first = $i; $last = $i; $num_columns++; } } if (!$num_columns) return ''; $out = ''; $out .= '<div class="column-blocks clearfix">'; $column_width = '25%'; // calculate percent width of a column for ($i = 0 ; $i < 4 ; $i++) { if ($columns[$i]) { if ($i == $first) { $margin_left_style = 'margin-left: 0px;'; } else { $margin_left_style = 'margin-left: 5px;'; } if ($i == $last) { $margin_right_style = 'margin-right: 0px;'; } else { $margin_right_style = 'margin-right: 5px;'; } $style = $margin_left_style . $margin_right_style; $out .= '<div class="column-block-wrapper" style="width: ' . $column_width . ';">'; $out .= '<div class="column-block" style="' . $style . '">'; $out .= render($columns[$i]); $out .= '</div></div> <!--/.column-block --><!--/.column-block-wrapper-->'; } } $out .= '</div> <!--/.column-blocks-->'; $out .= '<div class="spacer clearfix cfie"></div>'; return $out; }
Merci
Partager