Edited to add subform field type-specific answer:
Having looked at it properly, attaching your own layout to the subform field type is super-easy.
Create a layouts
folder in the same parent component folder (site or admin) as the XML file, and put your layout in it:
-com_myComponent
- controllers
- layouts
- mylayout.php
- models
- forms
Add layout="mylayout"
to your subform field in your XML and there you go.
Can't get much easier!
Should also note your layout file names can be the same as the default ones, yours will always get loaded if there's any conflict. So, for example, even though there's a subform layout called default.php
you can still name yours default.php
and it'll work fine.
Pre-edit answer:
Here's an example of how to include a layout from one of mine:
<?php echo JLayoutHelper::render('layouts.dupebutton', $dupeData, JPATH_COMPONENT_ADMINISTRATOR); ?>
- First argument is 'layoutFolder.layoutName'.
- Second argument is the data to pass to the layout (you'll be passing your form/fields).
- Third is the base path to use to search for the layout folder/file (in this case the path to the admin install of my component).
You need to add something similar to that when you want your layout to be rendered.
My com_myComponent
folder in Joomla's administrator
folder (ie. JPATH_COMPONENT_ADMINISTRATOR
) has this structure:
-com_myComponent
- classes
- controllers
- layouts
- dupebutton.php
- anotherlayout.php
Joomla's layout helper will pass the data you specified to the layout when it renders it. When the layout is rendered it will contain a pre-assigned variable called $displayData
. You can just use this variable as is, but it seems to be Joomla convention to add this line in the <?php
tags at the top of your layout files:
$data = $displayData;
Now it's just a case of building the layout using the form fields you want. Let me know if you also want examples of that, but it sounds like you know how already.
Incidentally, I'm pretty sure it is actually possible to select from form subgroups, but the syntax isn't very intuitive or well documented - last time I tried to do it I gave up much like you are now.
There are also multiple ways to achieve what you want, there are alternatives to using a layout. Still, it's as good a solution as any, so I'd stick with it.