Last active
August 29, 2015 14:04
-
-
Save cmalven/9695eb2bfb2f208e6f66 to your computer and use it in GitHub Desktop.
Twig: Add a class if a string containers a descender
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
{# If str contains a character with descender ('gjpqy'), outputs a class #} | |
{% macro descender_class(str) %} | |
{% set chars = [ 'g', 'j', 'p', 'q', 'y'] %} | |
{% set hasDescender = false %} | |
{% for c in chars %} | |
{% if c in str %} | |
{% set hasDescender = true %} | |
{% endif %} | |
{% endfor %} | |
{% if hasDescender %} | |
has-descender | |
{% endif %} | |
{% endmacro %} |
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
{% import "_helpers" as helpers %} | |
<h1 class="{{ helpers.descender_class(entry.myHeading) }}"> | |
{{ entry.myHeading }} | |
</h1> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment