we love CraftCMS and also typogrify plugin with Twig filter "|typogrify".

Now we are starting a web project that will combine Astro and CraftCMS will be used headless with the use of GraphQL API, which is very useful and excellently designed. We use latest CraftCMS 4.2.3 (PRO).

What we currently lack compared to Twig is the ability to use |typogrify. Do you know some way to ensure that we apply server-side typogrify to text values coming from GraphQL?

I know - correctly, the technology rendering the pages should take care of the typographical rules (so in our case Astro), but we have not yet found such a handy library as Typogrify.

Thanks for any suggestions on how to solve this problem in a clean way :)

1 Answer 1


So unfortunately, the short answer is that you can't. When you switch to using something else as the frontend for a Craft site (as opposed to Twig) you lose things like the Twig filter typogrify.

While technically it might be possible to write a layer on top of GraphQL that did this for you via PHP, I'm not sure I'd recommend it.

Instead, find JavaScript alternatives to the things you're used to in Twig.

  • Thank you, Andrew. We don't have much experience with implementing plugins in CraftCMS yet, but if possible, we will try to create a plugin that would allow you to set whether Typogrify should be applied to the GraphQL scheme. If this is set, the plugin will capture the output JSON of all GraphQL responses, recursively loop through it, and apply Typogrify for all text items. For performance reasons, there will eventually be the possibility to somehow configure the names of the keys in JSON, or something similar to XPath, to which Typogrify should possibly be applied. Just first ideas.
    – jan.reges
    Sep 22, 2022 at 16:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.