Drupal 7将短代码添加到wysiwyg中

时间:2014-11-06 11:13:31

标签: drupal drupal-7

我需要有可能将当前年份添加到网站的某个地方,这是wysiwyg。 类似于'现在是[年]'。 我可以为它创建模块,但它很复杂。有更好的主意吗? 我安装了ckEditor。

2 个答案:

答案 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);
}

答案 1 :(得分:0)

您可以使用token_insert来执行此操作。

安装此模块时,您可以按此插入年份:日期:[Y]

问候。