Hi,
I am back with MODX and I am building a new web site with members of a association.
I have a parent resource “Member” and I applied the member template.
As child resources, I created 5 profiles.
Form the Members resource, I use getResources to print the title, longtitle, a TV (portrait) and a text (content) of each child resource (the profile).
I do not really need a template for the profile resource, excepted for the TV. (For now, while I create a profile resource, I apply “empty” as a template.)
I created a TV to upload a portrait picture and I want to apply the TV to the profile resource.
However a TV must be allowed to use a template, isn’t?
My idea, is to create an empty template (with no HTML code) named “profile” and I apply it to each profile resources. In that way, I will be able to edit a profile resource and upload a picture for a member.
If in the future, if I create a profile resource, is there a way to automatically apply the profile template to the new profile resource, without a user action?
Or is there an other way to save a picture in a profile resource without the need of a template?
Do you even need a resource for these members? If you don’t need a page (with a URL) for every member, then maybe use MIGX instead.
There exists a system setting automatic_template_assignment. If set to “sibling”, a new resource should get the template from its siblings.
(In MODX 3, this currently only works if the template picker isn’t used → system setting enable_template_picker_in_tree = “No”).
You could also use Collections. If the “Members” resource is a Collections-Container, you can then define the template for newly created child resources.
I use ForceTemplate for this. It works really well for me.
In MODX3 you might want to disable the Template Picker [enable_template_picker_in_tree] system setting as ForceTemplate does not work with this.
Alternatively, there’s the automatic_template_assignment system setting which, if set to sibling, will pick the most commonly used template under your parent. This will affect your whole tree though - whereas ForceTemplate can be customised for each parent.
The problem with this solution is that the template isn’t forced until the new Resource is saved for the first time - so you won’t see your TV / form customisation until then.
There is a syntax error in Bob’s code. The closing bracket ) is missing:
if ($resource->get('parent') == 12) {
...
If you don’t intend the ‘member’ resources to ever be requested directly, it can be easier to use MIGX for such use cases. Instead of the resource fields “pagetitle”, “longtitle” etc., your define the necessary fields in MIGX and use “getImageList” to display the members (similar to “getResources”).
This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.