Widont() and smartypants() together—how to?

I have an array for a singers repertoire, including composers name and the work’s title. These works include often an opus number, so I would like to use the widont() function. But sometimes the title contains also quotes, and it would be fine to type straight ones and get the languages specific right ones. Here I use regularly the smartypants helper smartypants().
But how do I make both helpers working side-by-side?
My code looks like this:

    <?php foreach ($concerts as $concert): ?>
    <?php echo smartypants($concert['name']) ?> 
    <?php echo widont($concert['opus'] .' '. $concert['notes']) ?>
    <?php endforeach ?>

Is $concerts a structure field? Looks like you are using the yaml() method.
If you use the toStructure() method instead, you can do this:

    <?php foreach ($concerts as $concert): ?>
    <?php echo $concert->name()->smartypants()->widont() ?> 
    <?php echo $concert->opus()->widont() .' '. $concert->notes()->widont() ?>
    <?php endforeach ?>

Basically you can chain the two methods however you like.

1 Like

Note that you need the latest Kirby release, 2.3.2, to be able to use the $field->smartypants() method.

In all releases you should be able to “chain” the helper functions though:

  echo widont( smartypants( $textValue ) );
  // or
  echo smartypants( widont( $textValue ) );
1 Like

Thank you a lot!
Yes, it’s a structure field. Just chaining as fvsch explained is working perfectly.