1

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 }}

1 Answer 1

2

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 }}

2
  • 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
    Commented Aug 29, 2018 at 6:54
  • Unfortunately not Commented Aug 30, 2018 at 0:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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