Вопрос по темизации

Главные вкладки

Аватар пользователя molp molp 20 апреля 2014 в 16:23

Прошу подсказать, что я делаю неправильно при темизации.

В файле модуля нахожу необходимую функцию:

/**
 * Returns HTML for a date element formatted as a range.
 */

function theme_date_display_range($variables) {
  $date1 = $variables['date1'];
  $date2 = $variables['date2'];
  $timezone = $variables['timezone'];
  $attributes_start = $variables['attributes_start'];
  $attributes_end = $variables['attributes_end'];

  $start_date = '<span class="date-display-start"' . drupal_attributes($attributes_start) . '>' . $date1 . '</span>';
  $end_date = '<span class="date-display-end"' . drupal_attributes($attributes_end) . '>' . $date2 . $timezone . '</span>';

  // If microdata attributes for the start date property have been passed in,
  // add the microdata in meta tags.
  if (!empty($variables['add_microdata'])) {
    $start_date .= '<meta' . drupal_attributes($variables['microdata']['value']['#attributes']) . '/>';
    $end_date .= '<meta' . drupal_attributes($variables['microdata']['value2']['#attributes']) . '/>';
  }

  // Wrap the result with the attributes.
  return t('!start-date to !end-date', array(
    '!start-date' => $start_date,
    '!end-date' => $end_date,
  ));
}

Копирую код в файл template.php с соответствующими изменениями (в моем случае это просто замена разделителя "to" на "-").

Меняю имя функции в соответствии с тем что написано в README.txt модуля:

If the result is not quite what you need, you should be able to implement your
own theme preprocess functions, e.g. MYTHEME_preprocess_date_display_single()
or MYTHEME_preprocess_date_display_range() and alter the attributes to use the
values you want.

В итоге получаю:

/**
 * Returns HTML for a date element formatted as a range.
 */

function bartik_preprocess_date_display_range($variables) {
  $date1 = $variables['date1'];
  $date2 = $variables['date2'];
  $timezone = $variables['timezone'];
  $attributes_start = $variables['attributes_start'];
  $attributes_end = $variables['attributes_end'];

  $start_date = '<span class="date-display-start"' . drupal_attributes($attributes_start) . '>' . $date1 . '</span>';
  $end_date = '<span class="date-display-end"' . drupal_attributes($attributes_end) . '>' . $date2 . $timezone . '</span>';

  // If microdata attributes for the start date property have been passed in,
  // add the microdata in meta tags.
  if (!empty($variables['add_microdata'])) {
    $start_date .= '<meta' . drupal_attributes($variables['microdata']['value']['#attributes']) . '/>';
    $end_date .= '<meta' . drupal_attributes($variables['microdata']['value2']['#attributes']) . '/>';
  }

  // Wrap the result with the attributes.
  return t('!start-date - !end-date', array(
    '!start-date' => $start_date,
    '!end-date' => $end_date,
  ));
}

Разделитель по прежнему остается "to".
Кэш сбрасывал.

Комментарии

Аватар пользователя drupby drupby 20 апреля 2014 в 21:20

препроцесс функция и функция темизации - 2 большие разницы

"molp" wrote:
function bartik_preprocess_date_display_range($variables) {

должно быть
function bartik_date_display_range($variables) {

Аватар пользователя molp molp 21 апреля 2014 в 0:31

drupby wrote:
препроцесс функция и функция темизации - 2 большие разницы
"molp" wrote:
function bartik_preprocess_date_display_range($variables) {

должно быть
function bartik_date_display_range($variables) {

Во истину, спасибо!

Еще вопросик по новому формату года в php (http://php.net/manual/ru/function.date.php)
Пробую новый формат "o" вместо старого "Y" но в результате получаю XXXX XXXX вместо XXXX.

Аватар пользователя drupby drupby 21 апреля 2014 в 0:55

"molp" wrote:
Пробую новый формат "o" вместо старого "Y" но в результате получаю XXXX XXXX вместо XXXX.

значит не надо пробовать, а использовать Y