Custom Block Type: Programmatically accessing fields
Permalink
Hey there,
I'm afraid this is a rather obvious question but I just can't find anything about it in the documentation.
Say I have a (custom) block type. In its view, you can display the various fields by echoing $fieldname.
But how can I access these fields without using these shortcuts? For example I might want to iterate over all fields programatically.
It'd be great if someone could point me in the right direction.
Thanks a lot in advancec.
I'm afraid this is a rather obvious question but I just can't find anything about it in the documentation.
Say I have a (custom) block type. In its view, you can display the various fields by echoing $fieldname.
But how can I access these fields without using these shortcuts? For example I might want to iterate over all fields programatically.
It'd be great if someone could point me in the right direction.
Thanks a lot in advancec.
Hey,
thanks a lot for the quick reply.
Can you point me to a place in the documentation where I can find things like these?
thanks a lot for the quick reply.
Can you point me to a place in the documentation where I can find things like these?
I wish I could but that was not in the docs. I found it by going through the code.
If you look inside the folder concrete\src\block you will find files with block related functions. The one I gave you is in >BlockController.php which is the class block controllers extend.
If you look inside the folder concrete\src\block you will find files with block related functions. The one I gave you is in >BlockController.php which is the class block controllers extend.
In the view you can use
that will give you a Concrete\Core\Legacy\BlockRecord object with the fields and their values for the current block.
You can then just iterate over all fields like you would an array