Skip to content

Commit eef22d4

Browse files
committed
[TwigBridge] Add emojify twig filter
1 parent 227275a commit eef22d4

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

reference/twig_reference.rst

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,37 @@ serialize
645645
Accepts any data that can be serialized by the :doc:`Serializer component </serializer>`
646646
and returns a serialized string in the specified ``format``.
647647

648+
.. _reference-twig-filter-emojify:
649+
650+
emojify
651+
~~~~~~~
652+
653+
.. versionadded:: 7.1
654+
655+
The ``emojify`` filter was introduced in Symfony 7.1.
656+
657+
.. code-block:: twig
658+
659+
{{ text|emojify(catalog = null) }}
660+
661+
``text``
662+
**type**: ``string``
663+
664+
``catalog`` *(optional)*
665+
**type**: ``string`` | ``null``
666+
667+
The emoji set used to generate the textual representation (``slack``,
668+
``github``, ``gitlab``, etc.)
669+
670+
It transforms the textual representation of an emoji (e.g. ``:wave:``) into the
671+
actual emoji (👋):
672+
673+
.. code-block:: twig
674+
675+
{{ ':+1:'|emojify }} {# renders: 👍 #}
676+
{{ ':+1:'|emojify('github') }} {# renders: 👍 #}
677+
{{ ':thumbsup:'|emojify('gitlab') }} {# renders: 👍 #}
678+
648679
.. _reference-twig-tags:
649680

650681
Tags

string.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,23 @@ You can convert emojis to short codes with the ``emoji-text`` locale::
637637
$transliterator->transliterate('Breakfast with 🥝 or 🥛');
638638
// => 'Breakfast with :kiwifruit: or :milk-glass:
639639

640+
Inverse Emoji Transliteration
641+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
642+
643+
.. versionadded:: 7.1
644+
645+
The inverse emoji transliteration was introduced in Symfony 7.1.
646+
647+
Given the textual representation of an emoji, you can reverse it back to get the
648+
actual emoji thanks to the :ref:`emojify filter <reference-twig-filter-emojify>`:
649+
650+
.. code-block:: twig
651+
652+
{{ 'green heart'|emojify }} {# renders: 💚 #}
653+
{{ ':green_salad:'|emojify('slack') }} {# renders: 🥗 #}
654+
{{ ':turtle:'|emojify('github') }} {# renders: 🐢 #}
655+
{{ ':kiwi:'|emojify('gitlab') }} {# renders: 🥝 #}
656+
640657
Removing Emojis
641658
~~~~~~~~~~~~~~~
642659

0 commit comments

Comments
 (0)