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

  • 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 '18 at 6:54
  • Unfortunately not – Luke Holder Aug 30 '18 at 0:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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