Created
October 30, 2015 17:05
-
-
Save mortendk/39fb307c8deaa7d7d922 to your computer and use it in GitHub Desktop.
atom snippets for drupal twig
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
# Your snippets | |
# | |
# Atom snippets allow you to enter a simple prefix in the editor and hit tab to | |
# expand the prefix into a larger code block with templated values. | |
# | |
# You can create a new snippet in this file by typing "snip" and then hitting | |
# tab. | |
# | |
# An example CoffeeScript snippet to expand log to console.log: | |
# | |
# '.source.coffee': | |
# 'Console log': | |
# 'prefix': 'log' | |
# 'body': 'console.log $1' | |
# | |
'.text.html.twig': | |
# tags | |
'Tag twig function': | |
'prefix': '%%' | |
'body': '{% $1$2 %}\n $0\n{% end$1 %}' | |
'Tag twig Comment': | |
'prefix': '##' | |
'body': '{# $1 #}$0' | |
# debug | |
'Dump twig': | |
'prefix': 'dump' | |
'body': '{{ dump( ${1:content} ) }}$0' | |
'kint': | |
'prefix': 'kint debug' | |
'body': '{{ kint(${1:_context}) }}$0' | |
'dump twig all': | |
'prefix': 'dumpit' | |
'body': '<ol>\n{% for key, value in _context %} \n<li>{{ key }} </li> \n {% if loop.index == 2 %}}\n <pre>{{ dump( value ) }}</pre>\n{% endif %}\n{% endfor %}\n</ol>' | |
#block & extend | |
'Block twig': | |
'prefix': 'block' | |
'body': '{% block ${1:name} %}\n $0\n{% endblock %}' | |
'Extends twig block': | |
'prefix': 'extends' | |
'body': '{% extends \'${1:template}\' %}$0' | |
# set | |
'Set twig': | |
'prefix': 'set' | |
'body': '{% set ${1:var} %}\n $0\n{% endset %}' | |
'Set classes': | |
'prefix': 'setc' | |
'body': '{% set ${1:classes} = [\n \'field\',\n ]\n%}' | |
# if / else | |
'If (inline)': | |
'prefix': 'if' | |
'body': '{% if ${1:condition} %}$0{% endif %}' | |
'If ': | |
'prefix': 'ifb' | |
'body': '{% if ${1:condition} %}\n $0\n{% endif %}' | |
'If Else': | |
'prefix': 'ife' | |
'body': '{% if ${1:condition} %}\n $2\n{% else %}\n $0\n{% endif %}' | |
'For Loop': | |
'prefix': 'forloop' | |
'body': '{# for loop #}\n{% for item in items %}\n {{ items|length }} items.\n {% if loop.first %}\n {# first loop #}\n {% elseif loop.last %}\n {# last loop #}\n {% elseif loop.index == "2" %}\n {# 2nd loop #}\n {% elseif loop.revindex == "2" %}\n {# 2nd last reverse counted #}\n {% else %}\n {# default #}\n {% endif %}\n{% endfor %}' | |
'For': | |
'prefix': 'for' | |
'body': '{% for ${1:item} in ${2:items} %}\n $0\n{% endfor %}' | |
'For Else': | |
'prefix': 'fore' | |
'body': '{% for ${1:item} in ${2:items} %}\n $3\n{% else %}\n $0\n{% endfor %}' | |
'Else': | |
'prefix': 'else' | |
'body': '{% else %}\n $0' | |
# filter | |
'Filter': | |
'prefix': 'filter' | |
'body': '{% filter ${1:name} %}$0{% endfilter %}' | |
'Filter (Block)': | |
'prefix': 'filterb' | |
'body': '{% filter ${1:name} %}\n $0\n{% endfilter %}' | |
#drupal specific | |
'Region (Drupal)': | |
'prefix': 'region' | |
'body': '{% if page.${1:region} %}\n <${2:aside} role="complementary">\n {{ page.${1:region} }}\n </${2:aside}>\n{% endif %}' | |
## twig.html.twig ---------------------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment