Smarty pants and the Writer Field

I’m using the Writer Field a lot. Often when the client uses quote marks they are displaying as feet and inch marks (not proper typographers quote marks).

Is it possible to use Smarty Pants (smartypants | Kirby CMS) with the Writer Field and ->text()

or can Smarty Pants only be used with the Textarea Field and ->kirbytext() ?

See $field->smartypants() | Kirby CMS

Wow okay thanks that was fast

<?= $block->text()->permalinksToUrls()->smartypants() ?>

Can I do the above? Converting permalinks to usable links AND use smartypants? Is there an order?

As long as the field method returns a new field object (which is the case for both methods), you can apply them one after the other in no particular order in this case.

Is there a way to turn on Smarty Pants and Permalinks To URLs for the entire site in one go? In the configs? Without having to trawl through every template and snippet remembering to add them to every field?

From this page smartypants | Kirby CMS I can see how to turn on SmartyPants in the config file, but SmartyPants rules are only automatically applied whenever you use the ->kirbytext() or ->smartypants() field methods. Hence, it doesn’t automatically work for the Writer field content.

Presumably this means I have to add ->smartypants() to all the writer fields in my templates and snippets?

That is correct. To increase performance, Kirby doesn’t check the field type for each field that is printed in your templates. That’s why Kirby needs the explicit hints of what you want to do with each field. This can be ->kirbytext() for the full Markdown treatment (which includes SmartyPants if enabled via the global smartypants option) or ->smartypants() for fields that already contain HTML such as the Writer field.

The Textarea field and Markdown is unusable for 99% of clients. So, I’m surprised there is not a global site wide way of turning on SmartyPants for the Writer Field. Why would someone want some fields to have proper typographers quote marks, and some fields not?

Not every field in Kirby contains text. There are a lot of field types for structured data. If we applied SmartyPants to those non-text field types, this would break those fields completely. This is why we have context-sensitive field methods that perform the action that is needed for the respective field type and output situation.

We have plans to automatically detect field types, but as I wrote, this would currently have high performance implications. If we implement it, we want to do it in a way that performs well.

So SmartyPants can be applied to all Textarea fields in one config setting, but not the Writer field?

We have to manually remember to add the ->smartypants() field method to all Writer fields in our templates and snippets?

No it isn’t. It’s included in the ->kirbytext() method that you also apply to your textarea field to convert markdown etc.

The same principle applies to the writer field.

If you don’t want to apply ->permalinksToUrls() and ->smartypants(), you can create a custom field method that combines both methods. That way you would only have to apply one method to your fields, e.g. $field->toMyWriterFieldMethod

Oh okay, so because the Writer Field doesn’t have a method like the Textarea Field (->kirbytext()) it is tricky to automatically apply SmartyPants.

It’s also not automatically applied to the textarea field. It’s applied by adding ->kirbytext(). The same needs to be done for the writer field: either applying _>smartypants() or applying any other field method that also runs the smartypants conversion.

Okay, got you. Thanks