1

When you set up a table field column through the admin cp, you assign a name and a handle. When I var_dump the table field, all row data is referenced by column number. (e.g. col1, col5, col2, col3, col4)

    $partnerProducts = $currentPartner['0']->getContent()->productInfo;
    foreach ($partnerProducts as $pp){ echo ($pp['col2']); }

These columns may not be in order depending on how they were drag and dropped in the admin control panel, which is super confusing from the PHP plugin side. Is there any way to reference the table items by their cp handle?

You CAN do this from the twig side.

    {% for partnerProduct in partner.productInfo %}
        {{ partnerProduct.sku  }}
    {% endfor %}

I'm still not sure what the difference between $currentPartner['0']->getContent()->productInfo; and $currentPartner['0']->productInfo is but the latter works.

1

If you use:

$partnerProducts = $currentPartner['0']->productInfo;

Then you should be able to do:

foreach ($partnerProducts as $pp)
{
    echo ($pp['sku']);
}
  • So getContent() only returns the straight column values while the direct reference returns an array with the column values AND the table titles? – David Rampersad Jul 23 '15 at 22:42

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.