Skip to content

Commit 563b82e

Browse files
committed
[TwigBridge] Add emojify twig filter
1 parent e801d38 commit 563b82e

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
@@ -636,6 +636,37 @@ serialize
636636
Accepts any data that can be serialized by the :doc:`Serializer component </serializer>`
637637
and returns a serialized string in the specified ``format``.
638638

639+
.. _reference-twig-filter-emojify:
640+
641+
emojify
642+
~~~~~~~
643+
644+
.. versionadded:: 7.1
645+
646+
The ``emojify`` filter was introduced in Symfony 7.1.
647+
648+
.. code-block:: twig
649+
650+
{{ text|emojify(catalog = null) }}
651+
652+
``text``
653+
**type**: ``string``
654+
655+
``catalog`` *(optional)*
656+
**type**: ``string`` | ``null``
657+
658+
The emoji set used to generate the textual representation (``slack``,
659+
``github``, ``gitlab``, etc.)
660+
661+
It transforms the textual representation of an emoji (e.g. ``:wave:``) into the
662+
actual emoji (👋):
663+
664+
.. code-block:: twig
665+
666+
{{ ':+1:'|emojify }} {# renders: 👍 #}
667+
{{ ':+1:'|emojify('github') }} {# renders: 👍 #}
668+
{{ ':thumbsup:'|emojify('gitlab') }} {# renders: 👍 #}
669+
639670
.. _reference-twig-tags:
640671

641672
Tags

string.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,23 @@ Convert Slack short codes to emojis with the ``slack-emoji`` locale::
607607
$transliterator->transliterate('Menus with :green_salad: or :falafel:');
608608
// => 'Menus with 🥗 or 🧆'
609609

610+
Inverse Emoji Transliteration
611+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
612+
613+
.. versionadded:: 7.1
614+
615+
The inverse emoji transliteration was introduced in Symfony 7.1.
616+
617+
Given the textual representation of an emoji, you can reverse it back to get the
618+
actual emoji thanks to the :ref:`emojify filter <reference-twig-filter-emojify>`:
619+
620+
.. code-block:: twig
621+
622+
{{ 'green heart'|emojify }} {# renders: 💚 #}
623+
{{ ':green_salad:'|emojify('slack') }} {# renders: 🥗 #}
624+
{{ ':turtle:'|emojify('github') }} {# renders: 🐢 #}
625+
{{ ':kiwi:'|emojify('gitlab') }} {# renders: 🥝 #}
626+
610627
Removing Emojis
611628
~~~~~~~~~~~~~~~
612629

0 commit comments

Comments
 (0)