Last active
May 4, 2017 10:02
-
-
Save renebakx/485d582ee59a04c05ba5896698fbea86 to your computer and use it in GitHub Desktop.
Split a string into two colors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% macro split_title(text) %} | |
{% set text = render(text) %} {# only when doing twig for drupal 7 #} | |
{% set chunks = text|split('~') %} | |
{% for chunk in chunks %} | |
{{ (loop.index0 is odd)?"<em>"~chunk~"</em>":chunk}} | |
{% endfor %} | |
{% endmacro %} | |
<h3>{{ split_title('This is a ~text~ with some ~colors~') }}</h3> | |
<h3>This is a <em>text</em> with some <em>colors</em></h3>` | |
CSS example : | |
h3 em { | |
color: #CAFE00; | |
font-style: normal; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment