Hi,
I'm working on a prototype for a little extension which does the following:
It takes a +block-variable and splits the contents into different pieces, according to their type ($block->type
). For my case as an example:
Each header (h1) is wrapped in a <div>
, including all following entries until the next header (h1).
The extension allows to define:
- the +content-block
- the desired type of "container" for each "collection" (eg
<div>
)
- the delimiting content-type (e.g. Header or Image)
- an optional class for each piece (container, delimiting content-type, content)
- an exclude / include list (which block-contents to skip/include, eg. skip images) (this is work in progress).
The extension returns an array with each of these containers.
return $output;
I have been able to bolt this together with a lot of googling and even more trial an error (I understand some basic concepts of programming but definitely don't "speak" or "write" php) and of course the documentation and existing extensions.
I'm now able to call the extension from my template as
<@ fkap/getblocks { option: "option", option2: "option"} @>
But I'm lost as to how I would now be able to loop through the entries in the returned array.
The extension is definitely working to some degree, as if I put in return $output[0];
the first entry in the array is rendered within the page.
Background:
I want to display the contents of the +main content block differently on mobile (or more generally: I would like to keep the main content together but have a certain degree of freedom as to how to lay it out).
I'm happy to post the code if more info is needed. It's basically
foreach($main->blocks as $block) {
…
}
with different cases (thanks to the hint to the Revitron-theme in this discussion)
– however, be gentle … it's really my first step into writing code and I'm sure it's full of embarassingly stupid mistakes … also there might be a much simpler way to achieve this, of course (then it would just have been a lot of fun learning something new).
Thanks for any pointers or help.
Florian