The following code works great in a template.

{% set priceProduct = currentUser.priceTable.relatedTo({    
    targetElement: product.id,
    field: 'product'
}).one() %}

{{ priceProduct.price }}

Where priceTable is a Super Table, product.id is from an entry element (we're in loop).

'product' is an entry field in the Super Table row and 'price' is a plaintext field in the Super Table row.

How might we go about replicating this functionality in a plugin?

Craft Pro 3.0.29

Super Table 2.0.11

1 Answer 1

$element = Craft::$app->getUser()->getIdentity()->priceTable->relatedTo([
    'targetElement' => $product->id,
    'field' => 'product'

But to be honest your code in Twig should not work as expected since you only grab the query and modify it. Your output is your search criteria, not the value of an element.

  • Thank you. (I was so close!) Yeah, I wondered about that. Not getting a deprecation warning either. Fixed in the edit.
    – Steve Mock
    Nov 9, 2018 at 15:58
  • Nothing was deprecated, you just display the criteria of your ElementQuery there is nothing wrong about that, it is just not what you want Nov 9, 2018 at 16:00

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.