super-table
super-table copied to clipboard
How can i print content for each field using PHP?
Question
How can i print content for each field using PHP?
There is my code:
// Get Entry
$enties = Entry::findOne(['id' => 1525, 'siteId' => 7])->contentBlocks->all();
// Get SuperTable block types
$stFields = Craft::$app->getFields()->getAllFields(
'superTableBlockType:' .
SuperTable::$plugin->getService()->getBlockTypesByFieldId($field->id)[0]->uid
);
// Print each SuperTable fielId and fieldHandle
foreach ($stFields as $stField) {
print $stField->id . " " . $stField->handle . "\n";
}
Thaks.
Additional context
No response
There's an example on the docs, but it's really just like Twig
$entry = Entry::find()->id(1234)->one();
foreach ($entry->mySuperTableField->all() as $block) {
foreach ($block->getFieldLayout()->getCustomFields() as $field) {
$value = $block->getFieldValue($field->handle);
var_dump($value);
}
}
If you know the field you want to fetch content for, that's simpler.
$entry = Entry::find()->id(1234)->one();
foreach ($entry->mySuperTableField->all() as $block) {
$value = $block->myFieldHandle;
}