'
)}}
{{ _self.codeBlock('Conditionals around position values', '
{% if '
~ data.sampleTag
~ ' in [\'left\', \'right\'] %}\n'
~ data.whitespace
~ '{# ... #}\n'
~ '{% elseif '
~ data.sampleTag
~ ' == \'center\' %}\n'
~ data.whitespace
~ '{# ... #}\n'
~ '{% endif %}'
)}}
{{ _self.codeBlock('Switch statement for all values', '
{% switch '
~ data.sampleTag
~ ' %}\n'
~ data.whitespace
~ '{% case \'left\' %}\n'
~ data.whitespace ~ data.whitespace
~ '{# ... #}\n'
~ data.whitespace
~ '{% case \'center\' %}\n'
~ data.whitespace ~ data.whitespace
~ '{# ... #}\n'
~ data.whitespace
~ '{% case \'right\' %}\n'
~ data.whitespace ~ data.whitespace
~ '{# ... #}\n'
~ data.whitespace
~ '{% case \'full\' %}\n'
~ data.whitespace ~ data.whitespace
~ '{# ... #}\n'
~ data.whitespace
~ '{% case \'drop-left\' %}\n'
~ data.whitespace ~ data.whitespace
~ '{# ... #}\n'
~ data.whitespace
~ '{% case \'drop-right\' %}\n'
~ data.whitespace ~ data.whitespace
~ '{# ... #}\n'
~ '{% endswitch %}'
)}}
{% endmacro -%}
{%- macro cs_RadioButtons(data) %}
{{ _self.codeBlock('The Selected value\'s option', '
{{ ' ~ data.sampleTag ~ ' }}'
)}}
{{ _self.codeBlock('The Selected value\'s label', '
{{ ' ~ data.sampleTag ~ '.label }}'
)}}
{{ _self.codeBlock('Loop through all available options', '
\n'
~ data.whitespace ~ '{% for option in '
~ data.sampleTag
~ '.options %}\n'
~ data.whitespace ~ data.whitespace
~ '- {{ option }}
\n'
~ data.whitespace
~ '{% endfor %}\n'
~ '
'
)}}
{% endmacro -%}
{%- macro cs_RichText(data) %}
{{ _self.codeBlock('Field name', '
{{ ' ~ data.sampleTag ~ ' }}'
)}}
{{ _self.codeBlock('"If exists" conditional', '
{% if ' ~ data.sampleTag ~ '|length %} ... {% endif %}'
)}}
{% endmacro -%}
{%- macro cs_SmartMap_Address(data) %}
{{ _self.codeBlock('Individual address fields', '
{{ ' ~ data.sampleTag ~ '.street1 }}\n'
~ '{{ ' ~ data.sampleTag ~ '.street2 }}\n'
~ '{{ ' ~ data.sampleTag ~ '.city }}\n'
~ '{{ ' ~ data.sampleTag ~ '.state }}\n'
~ '{{ ' ~ data.sampleTag ~ '.zip }}\n\n'
~ 'Latitude: {{ ' ~ data.sampleTag ~ '.lat }}\n'
~ 'Longitude: {{ ' ~ data.sampleTag ~ '.lng }}\n\n'
~ '{# Only available in proximity search results #}\n'
~ 'Found {{ ' ~ data.sampleTag ~ '.distance | number_format(1) }} miles away.\n'
)}}
{{ _self.codeBlock('Combined address output', '
{# On 3 lines #}\n'
~ '{{ '
~ data.sampleTag ~ '.format'
~ ' }}\n\n'
~ '{# On 2 lines #}\n'
~ '{{ '
~ data.sampleTag ~ '.format(true)'
~ ' }}\n\n'
~ '{# On 1 line #}\n'
~ '{{ '
~ data.sampleTag ~ '.format(true, true)'
~ ' }}'
)}}
{{ _self.codeBlock('"If address is not empty" conditional', '
{% if not ' ~ data.sampleTag ~ '.isEmpty %} ... {% endif %}'
)}}
{{ _self.codeBlock('"If address has coordinates" conditional', '
{% if ' ~ data.sampleTag ~ '.hasCoords %} ... {% endif %}'
)}}
{% endmacro -%}
{%- macro cs_Table(data) %}
{#
Some whitespace setup code so we can use the previously defined
macro to verticaly align comments in code using strRepeat
#}
{%- set rowWhitespace = [] -%}
{%- for col in data.field.settings.columns -%}
{%- set rowWhitespace = rowWhitespace|merge([col.handle|length]) -%}
{%- endfor -%}
{#
We need to pass a single string through the .codeBlock macro
so we're going to build our list of column names and tags before
we build out the full code snippet string to pass through
#}
{%- set rowBlock -%}
{%- for col in data.field.settings.columns -%}
{{-
data.whitespace ~ data.whitespace
~ '{{ row.' ~ col.handle ~ ' }} '
~ _self.strRepeat(' ', max(rowWhitespace) - col.handle|length)
~ '{# ' ~ col.type ~ ' #}\n'
-}}
{%- endfor -%}
{%- endset -%}
{{ _self.codeBlock('Table Structure', '
{% if ' ~ data.sampleTag ~ '|length %}\n'
~ data.whitespace
~ '{% for row in ' ~ data.sampleTag ~ ' %}\n'
~ rowBlock
~ data.whitespace
~ '{% endfor %}\n'
~ '{% endif %}'
, 'This the general structure of the table and column handles (and types). If there are any default row values they will are displayed below this structure code block.')}}
{% if data.field.settings.defaults %}
Default Values
Row # |
{%- for col in data.field.settings.columns -%}
{{ col.heading }} |
{% endfor %}
{%- for row, cols in data.field.settings.defaults -%}
{{ loop.index }} |
{%- for col in cols -%}
{{ col }} |
{%- endfor -%}
{%- endfor -%}
{% endif %}
{% endmacro -%}
{%- macro cs_Tags(data) %}
{{ _self.codeBlock('Set a variable for future template use', '
{% set myTags = ' ~ data.sampleTag ~ ' %}'
)}}
{{ _self.codeBlock('Check if any tags exist', '
{% if ' ~ data.sampleTag ~ '|length %} ... {% endif %}'
)}}
{{ _self.codeBlock('Loop through the selected tags', '
{% for myTag in '
~ data.sampleTag
~ ' %}\n'
~ data.whitespace
~ '...\n'
~ '{% endfor %}'
)}}
{{ _self.codeBlock('Order by parameters', '
{% set myTags = ' ~ data.sampleTag ~ '.order(\'title\') %}'
)}}
{{ _self.codeBlock('Avoid a loop if your field limits to 1 user', '
{% if '
~ data.sampleTag
~ '.first() %}\n'
~ data.whitespace
~ '...\n'
~ '{% endif %}'
)}}
{% endmacro -%}
{%- macro cs_Users(data) %}
{{ _self.codeBlock('Set a variable for future template use', '
{% set myUsers = ' ~ data.sampleTag ~ ' %}'
)}}
{{ _self.codeBlock('Check if any users were selected', '
{% if ' ~ data.sampleTag ~ '|length %} ... {% endif %}'
)}}
{{ _self.codeBlock('Loop through the selected users', '
{% for myUser in '
~ data.sampleTag
~ ' %}\n'
~ data.whitespace
~ '...\n'
~ '{% endfor %}'
)}}
{{ _self.codeBlock('Filter by parameters', '
{% set authors = ' ~ data.sampleTag ~ '.group(\'groupName\') %}'
)}}
{{ _self.codeBlock('Avoid a loop if your field limits to 1 user', '
{% set myUser = '
~ data.sampleTag
~ '.first() %}\n'
~ '{% if myUser %}\n'
~ data.whitespace
~ '...\n'
~ '{% endif %}'
)}}
{% endmacro -%}
{%- import _self as csMacro -%}
{{ cs.pageTitle }} — for {{ siteName }}
{% for field in cs.fields %}
{{ field.name }}
{{ field.type|replace('_', ' ')|replace('/(.)([A-Z])/', '$1 $2')|title }}
{# ---------------------------------------------
Dynamically check for a macro to build code snippets
for this field type. If it doesn't exist, we have
a fallback message to show.
--------------------------------------------- #}
{{ attribute(csMacro, 'cs_' ~ field.type) is defined
? attribute(csMacro, 'cs_' ~ field.type, [
{
'sampleTag' : sampleTag ~ '.' ~ field.handle,
'field' : field,
'whitespace': whitespace
}])
: '
There are no code samples available for this field type yet.
'
}}
{% endfor %}
Wishful Thinking?
Nice try searching for that.
No fields were found. Perhaps try adding some fields in the control panel, changing your search, or wishing a little harder.
{# ---------------------------------------------
The Craft Field Cheat Sheet
Copyright (c) 2015 Focus Lab, LLC
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------- #}