Tuesday 15 February 2011

Drupal 7 add shortcode into wysiwyg -



Drupal 7 add shortcode into wysiwyg -

i need possibility add together current year somewhere on site in wysiwyg. 'now [year] year'. can create module it, it's complicated. there improve idea? , have ckeditor installed.

you can utilize https://www.drupal.org/project/shortcode, , extend create own custom shortcode , utilize in ckeditor.

custom shortcode creation reference link: http://briannadeleasa.com/blog/drupal-php/shortcodes-drupal-yes-you-can

for example, check out these 3 functions create our button shortcode:

/** * define our process callback function our [button] shortcode. * takes in our shortcode attributes shortcode , if empty, sets property * default value stated in function. pass in our attributes * theme() function outputs html. * * $attrs = shortcode_attrs(array( * 'attribute' => 'default_value_goes_here' * ), */ function custom_shortcodes_shortcode_button($attrs, $text) { $attrs = shortcode_attrs(array( 'link' => 'http://mywebsite.com' ), $attrs ); homecoming theme('shortcode_button', array('link' => $attrs['link'], 'text' => $text)); } /** * function uses attributes passed in homecoming html of shortcode. */ function theme_shortcode_button($vars) { homecoming '<div class="button"><a href="' . $vars['link'] . '">' . $vars['text'] . '</a></div>'; } /** * function outputs tips user beneath wysiwyg editor know * shortcode , how utilize it. */ function custom_shortcodes_shortcode_button_tip($format, $long) { $output = array(); $output[] = '<p><strong>' . t('[button link="http://urlhere.com"]text[/button]') . '</strong> '; if ($long) { $output[] = t('outputs text displayed button, links specified url.') . '</p>'; } else { $output[] = t('outputs text links url.') . '</p>'; } homecoming implode(' ', $output); }

drupal drupal-7

No comments:

Post a Comment