我需要在wysiwyg网站上的某个地方添加当前年份的可能性。 类似于“现在是[年]年”。 我可以为它创建模块,但它很复杂。有更好的主意吗? 我已经安装了ckEditor。Drupal 7将短代码添加到wysiwyg
0
A
回答
0
1
您可以使用https://www.drupal.org/project/shortcode,并扩展它以创建自己的自定义短代码并在ckeditor中使用它。
自定义简码创建参考链接: http://briannadeleasa.com/blog/drupal-php/shortcodes-drupal-yes-you-can
例如,检查出这3个函数来创建我们的按钮简码:
/**
* Define our process callback function for our [button] shortcode. This
* takes in our shortcode attributes from the shortcode and if empty, sets the property
* to the default value stated in this function. We then pass in our attributes to the
* theme() function which outputs the 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
);
return theme('shortcode_button', array('link' => $attrs['link'], 'text' => $text));
}
/**
* This function uses the attributes passed in to return the HTML of this shortcode.
*/
function theme_shortcode_button($vars) {
return '<div class="button"><a href="' . $vars['link'] . '">' . $vars['text'] . '</a></div>';
}
/**
* This function outputs some tips to the user beneath the WYSIWYG editor so they know
* what the shortcode does and how to use 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 that is displayed as a button, which links to a specified URL.') . '</p>';
}
else {
$output[] = t('Outputs text that links to a URL.') . '</p>';
}
return implode(' ', $output);
}