FormHelpers filters

error_class filter

(up)

Outputs error class if argument is not empty. Example: Using error_class to show output an error class.

<input class="{{ form.errors.description | error_class }}" />

inline_errors filter

(up)

Outputs error fields inline in paragraph. Example: Using inline_errors to show errors inline.

{{ form.errors.description | inline_errors }}

ParamFilter filters

to_param filter

(up)

Converts a supplied drop to URL parameter if possible. Example: Using to_param filter in liquid.

<h1>Signup to a service</h1>
<a href="{{ urls.signup }}?{{ service | to_param }}">Signup to {{ service.name }}</a>

Common filters

group_by filter

(up)

Group collection by some key. Example: Group applications by service.

{% assign grouped = applications | group_by: 'service' %}
{% for group in grouped %}
  Service: {{ group[0 }}
  {% for app in group[1] %}
    Application: {{ app.name }}
  {% endfor %}
{% endfor %}

any filter

(up)

True if any string in the collection equals to the parameter. Example: Are there any pending apps of the current account?

{% assign has_pending_apps = current_account.applications | map: 'state' | any: 'live' %}

stylesheet_link_tag filter

(up)

Stylesheet link

javascript_include_tag filter

(up)

Javascript includes tag.

image_tag filter

(up)

Outputs an tag using the parameters as its src attribute.

{{ 'http://example.com/cool.gif' | image_tag }}
# => <img src="http://example.com/cool.gif" >

mail_to filter

(up)

Converts email address to a 'mailto' link.

{{ 'me@there.is' | mail_to }}
# => <a href="mailto:me@there.is">me@there.is</a>

html_safe filter

(up)

Marks content as HTML safe so that it is not escaped.

pluralize filter

(up)

Converts word to plural form.

delete_button filter

(up)

Generates a button to delete a resource present on the URL. First parameter is a URL, second is a title. You can also add more HTML tag attributes as a third parameter.

To add a confirmation dialog, add a confirm attribute with a confirmation text

{{ 'Delete Message' | delete_button: message.url, class: 'my-button',
  confirm: 'are you sure?' }}

delete_button_ajax filter

(up)

Generates a button to delete a resource present on the URL using AJAX. First parameter is a URL, second is a title.

To add a confirmation dialog, add a confirm attribute with a confirmation text.

{{ 'Delete Message' | delete_button_ajax: message.url, confirm: 'are you sure?' }}

update_button filter

(up)

Generates a button to 'update' (HTTP PUT request) a resource present on the URL. First parameter is a URL, second is a title. You can also add more HTML tag attributes as a third parameter.

To change the text of the submit button on submit, add a disable_with attribute with a the new button text.

{{ 'Resend' | update_button: message.url, class: 'my-button', disable_with: 'Resending…' }}

update_button_ajax filter

(up)

Generates a button to 'update' (HTTP PUT request) a resource present on the URL using AJAX. First parameter is a URL, second is a title. You can also add more HTML tag attributes as a third parameter.

To change the button text on submit, add a disable_with attribute with a the new button text.

{{ 'Resend' | update_button: message.url, class: 'my-button', disable_with: 'Resending…' }}

create_button filter

(up)

Generates a button to create a resource present on the URL. First parameter is a URL, second is a title. You can also add more HTML tag attributes as a third parameter.

To change the button text on submit, add a disable_with attribute with a the new button text.

{{ 'Create Message' | create_button: message.url, disable_with: 'Creating message…' }}

create_button_ajax filter

(up)

Generates a button to create a resource present on the URL using AJAX. First parameter is a URL, second is a title. You can also add more HTML tag attributes as a third parameter.

To change the button text on submit, add a disable_with attribute with a the new button text.

{{ 'Create Message' | create_button: message.url, disable_with: 'Creating message…' }}

regenerate_oauth_secret_button filter

(up)

link_to filter

(up)

Create link from given text

{{ "See your App keys" | link_to:'/my-app-keys' }}

dom_id filter

(up)