Replace German quotation marks („ … “) with smartypants?

I’d like to replace German quotation marks („ … “) of a text entered into a textarea field to Guillemets (» … «). I’m trying to use the smartypants method to do so, but the text keeps being rendered with the default quotations marks.

In my config.php I have set the following:

<?php

  return [

    'debug'  => true,

    'smartypants' => [
      'doublequote.open' => '&#187;',
      'doublequote.close' => '&#171;',
    ],

  ];

?>

In the template I’m fetching and rendering the text like this:

<?php $someText_withGuillemets = $page->someText()->kirbyText()->smartypants() ?>

<div class="text-section">
  <div class="text-section__content">
    <?= $someText_withGuillemets ?>
  </div>
</div>

This is how the text is entered into the field:

This is how it is currently being rendered:

When I enter it with regular quotation marks ("…"), like so…

…the text renders as intended:

Can German quotation marks not be detected with smartypants?

I’d say you probably have to replace not

'doublequote.open' => '&#187;',
'doublequote.close' => '&#171;',

but maybe

'smart_doublequote_open',
'smart_doublequote_close',

(Not tested)

Thanks. Just tested it, no luck unfortunately

SmartyPants only replaces plain ASCII quotes to the configured format, but it cannot detect other types of quotes.

A workaround could be to first dynamically replace the German quotation marks to ASCII ones and then call SmartyPants afterwards:

$someText_withGuillemets = $page->someText()->callback(function ($field) {
  $field->value = str_replace(['„', '“'], '"', $field->value);
  return $field;  
})->kirbyText()->smartypants();
3 Likes