In Craft 2, is it possible to query a specific element by ID in Twig? They aren't mentioned in the docs.

I was trying things like these but without success:

{{ craft.commerce.paymentMethods.id(1).name }}
up vote 2 down vote accepted

Commerce 1:

{% set paymentMethod = null %}
{% for pm in craft.commerce.paymentMethods %}
    {% if pm.id == 2 %}{% set paymentMethod = pm %}{% endif %}
{% endfor %}

{{ paymentMethod.name }}

Commerce 2:

{{ craft.commerce.gateways.getGatewayById(2).name }}

  • For Commerce 1, it only seems to work for payment methods that are available for checkout. Is there a way to query methods that are not available for checkout? – biko Aug 29 at 6:54
  • Unfortunately not – Luke Holder Aug 30 at 0:40

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.