Drupal 7
Custom Blocks with Images
Very useful post by Four Kitchens developer. http://fourkitchens.com/blog/2012/07/18/building-custom-blocks-drupal-7
- Login to post comments
Misc jQuery Code
Attach a click event to webform 'Next page' button.
Drupal.behaviors.onlineApp = {
attach: function (context, settings) {
jQuery('#edit-actions').click(function(event) {
event.preventDefault();
alert('OK');
console.log('XXXX started.');
});
}
};- Login to post comments
Print Node Variables in Page.tpl.php
Add the following in your template.php hook_preprocess_page function:
<?php
function YOUR-THEME_preprocess_page(&$variables) {
if(isset($variables['node']) && $variables['node']->type == 'YOUR-CONTENT-TYPE') {
if ($node = menu_get_object()) {
$variables['highlight'] = field_view_field('node', $node, 'field_highlight_text', 'full');
}
}
}
?>Note here that if your content type is something like "corporate-property" then you will have to use "corporate_property" in place of "YOUR-CONTENT-TYPE" (notice the underscore instead of a dash).
Add Custom CSS To Your Edit Forms In Drupal 7
Add the following to your site specific custom module.
function MODULE-NAME_form_alter(&$form, &$form_state, $form_id) {
switch ($form_id) {
case 'YOUR-FORM-ID':
global $theme;
$form['#attached']['css'] = array(
drupal_get_path('theme', 'YOUR-THEME-NAME') . '/css/edit-forms.css',
);
break;
}
}Then add the edit-forms.css style sheet, put in your styles and clear the cache.
- Login to post comments
Add JavaScript To The Front Page Of Your Drupal 7 Site
Put in template.php:
function richdale_preprocess_page(&$variables) {
if ($variables['is_front']) {
$options = array(
'type' => 'file'
);
drupal_add_js(drupal_get_path('theme', 'richdale'). '/scripts/preload_images.js', $options);
$variables['scripts'] = drupal_get_js();
}- Login to post comments
D7 Multi-Step Forms
This is simply a collection of resources I've stumbled upon while searching for D7 multi-step stuff.
http://growingventuresolutions.com/blog/drupal-7-multistep-forms-using-v...
http://drupal.org/project/multistep
- Login to post comments
How to use Drupal 7's built-in Ajax Framework
Awesome videocast on using D7's ajax framework by Sean Buscay.
http://seanbuscay.com/ajax-reader-demo
https://github.com/seanbuscay/drupal-ajax-demo
- Login to post comments
Loop Through Multiple Image Fields in Drupal 7
<?php
$node = node_load($nid);
$image = field_get_items('node', $node, 'field_NAME');
foreach ($image as $key=>$value) {
$output = field_view_value('node', $node, 'field_NAME', $image[$key], array(
'type' => 'image',
'settings' => array(
'image_style' => 'thumbnail', //place your image style here
'image_link' => 'content',
),
));
print render($output);
}
?>- Login to post comments
Add a Class Selector to Menu Items
Sometimes you need a class selector in order to more easily target some particular item, such as a menu link.
Drop the following into the template.php file for your theme, clear your caches and all your menu items will have classes like "menu-123".
/**
* Add unique class (mlid) to all menu items.
*/
function YOUR-THEME-NAME_menu_link(array $variables) {
$element = $variables['element'];
$sub_menu = '';
$element['#attributes']['class'][] = 'menu-' . $element['#original_link']['mlid'];
if ($element['#below']) {
$sub_menu = drupal_render($element['#below']);
}
How to programmatically create nodes, comments and taxonomies in Drupal 7
Awesome post by Tim "TimOnWeb" Kamanin about programmatically creating nodes, comments and taxonomies in Drupal 7.
- Login to post comments