Get Express Values from page attribute
Permalink 1 user found helpful
Hi,
I created a page attribute (express object type). How can I programmatically retrieve data in object after getting the value with this code?
I created a page attribute (express object type). How can I programmatically retrieve data in object after getting the value with this code?
$obj = $c->getAttribute('my_attribute_handle'); ...
This fetches the whole record as a string. Is there a way to access a field inside object separately?
Hi Sepehr,
Here is an example of retrieving an Express Entity page attribute and working with its Express Entry.
- "test_express" is an Express Entity attribute applied to a page
Here is an example of retrieving an Express Entity page attribute and working with its Express Entry.
- "test_express" is an Express Entity attribute applied to a page
$c = Page::getCurrentPage(); // Concrete\Core\Entity\Attribute\Value\Value\ExpressValue $testExpressValue = $c->getAttribute('test_express'); if ($testExpressValue) { // array of Concrete\Core\Entity\Express\Entry $testExpressEntryArray = $testExpressValue->getSelectedEntries(); // Concrete\Core\Entity\Express\Entry $testExpressEntry = $testExpressEntryArray[0]; // array of Concrete\Core\Entity\Attribute\Value\ExpressValue $attributes = $testExpressEntry->getAttributes(); foreach ($attributes as $attribute) { // Concrete\Core\Entity\Attribute\Value\ExpressValue echo '<p>' . $attribute->getAttributeKey()->getAttributeKeyName() . ': ' . $attribute->getDisplayValue() . '</p>'; } }
Hi Karl,
Thank you very much for the answer. Another thing, if I know the Express fields handle, is there a way to get it directly without looping through attributes? e.g I know this Express Object has a first_name and last_name field. Can I get the value with something like:
$attributes['first_name']
Thank you very much for the answer. Another thing, if I know the Express fields handle, is there a way to get it directly without looping through attributes? e.g I know this Express Object has a first_name and last_name field. Can I get the value with something like:
$attributes['first_name']
@Sepehr
Once you have the Express Entry, you can use the Express object magic methods to get attributes.
Once you have the Express Entry, you can use the Express object magic methods to get attributes.
$c = Page::getCurrentPage(); // Concrete\Core\Entity\Attribute\Value\Value\ExpressValue $testExpressValue = $c->getAttribute('test_express'); if ($testExpressValue) { // array of Concrete\Core\Entity\Express\Entry $testExpressEntryArray = $testExpressValue->getSelectedEntries(); // Concrete\Core\Entity\Express\Entry $testExpressEntry = $testExpressEntryArray[0]; // get attributes using express magic methods // Example: default install Contact express object // - contact_question_first_name // - contact_question_last_name // - contact_question_email_address // - contact_question_subject // - contact_question_message
Viewing 15 lines of 21 lines. View entire code block.
For anyone trying to work with images in Express objects:
** replace ImageAttributeHandle with the handle of your image
$photoFileObject = $entry->getImageAttributeHandle(); if (is_object($photoFileObject)) { $photoFileObjectVersion = $photoFileObject->getVersion(); $photoRelativePath = $photoFileObjectVersion->getRelativePath(); }
** replace ImageAttributeHandle with the handle of your image