ModX getResources displays child resources as well as parent level resources - content-management-system

I have getResources call:
[[!getResources? &parents=`[[*id]]` &limit=`15` &tpl=`contentsectiontpl` &sortdir=`ASC` &sortby=`menuindex` &includeContent=`1`]]
In a parent resource.
I wish to only display the child resources of this parent, but the above displays both the child resources, and the resources on the same level as the parent.
Does anyone know the correct way to achieve displaying only the child resources without using the parents ID directly?

If youre really getting the parents siblings, you must be specifying the wrong ID. Make sure you shouldnt be using [[+id]] instead of [[*id]], in case youre listing some sort of submenu or such.

Try '-1' for &parents
Comma-delimited list of ids serving as parents. Use -1 to ignore
parents when specifying resources to include. If this is not done,
getResources assumes &parents as the current resource and reads it's
childs from there (plus the resources given in &resources = unexpected
results).
Though it should not be showing the parents sibling resources - I have never seen getResources do this! you are using the call directly in the parent or including it somehow?
If possible you can also hide the parent resource and/or use the hideContainers parameter or possibly the resources parameter to exclude specific [parent] resources.

Do not make this call in Content field in this parent resource - do it in template. The call is correct, must be something else wrong...

You could also specify the template, if it's different between parent and child.
Examples:
&where=`{"template:=":8}`
&where=`{"template:=":1, "OR:template:=":2}`
&where=`{"template:IN":[1,2,3]}`

Related

TYPO3 9.5 Sorting of child-elements from parent

I have a problem finding a simple and easy solution to sort child-elements in it's parent. I don't want to have them sorted by the sorting-property of the child but some other value (in this example sort_value).
The parent has the property child_elements, and the child has a property sort_value.
I've already tried adding the following statement to the defaultOrderings of the ParentRepository:
'child_elements.sort_value' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING
I've also tried with childElements.sort_value and childElements.sortValue but that didn't work in either way.
I've found some solutions like sorting the children in the template using vhs-viewhelper or with injecting the childRepository into the ParentModel which then calls the findAll-function on the child in the getter-function of the parent (which is really dirty)...
Is there a mistake I'm not aware of in the defaultOrderings-statement? Or is there simply not such a simple way to do it?
The childRepository already has it's defaultOrderings set to the sortValue. The functions used for getting the parent is findAll or findByUid so no custom repository function.
What I want is to get the parent-object with it's sorted children by the children's field sort_value.
Thanks for your help.

AEM - How to pass data to a component

Usually an AEM component is retrieving its data from a JCR node, but I was wondering whether it's possible to pass data to it in HTL. Sure, there's data-sly-resource, but as far as I know this way you can only pass a JCR node.
So in an actual case I've got data in a model that's retrieved from elsewhere. Yet I'd like to use existing components. I'm aware that the data must at least match the component-types' model.
But what if the component I'd like to use is using an model that got its data injected like
#Inject
#Optional
String[] itemList;
So in my stubborn thoughts it should be possible to somehow pass a string array like
<div data-sly-resource="${myModel.aStringArray # resourceType='my/component' }"></div>
But like mentioned above this seems to be meant for passing nodes only.
Is there any way to accomplish passing data directly to a component (other than creating a template)?
You can pass additional information in the form of request attributes or selectors
Selectors
Selectors are the most straight forward of passing simple information. This is an array of strings that can be passed. This is quite useful to data that can act as flags ex:
Variant/Mode of the component
index of the component in a list if it is being included in a loop.
ID of the parent when building things like accordion, tabs
This approach is an abuse of selectors, but IMHO as long as you know what you are doing this shouldn't be a major concern.
<article data-sly-resource="${'path/to/resource' # selectors=['s1', 's2']}"></article>
You can add, replace or remove selectors while including the component. Checkout the documentation for the syntax. https://docs.adobe.com/content/help/en/experience-manager-htl/using/htl/block-statements.html#resource
Request Attributes
This option allows you to add custom request attributes to the component request. This can be used to pass objects as parameters to the component while including them.
These are standard http request attributes with convince of scoping them to a particular instance of script/resource inclusion. To use this you will end up needing a model class or use-js as there is little support to compose the data to be passed along in sightly.
<sly data-sly-use.settings="com.adobe.examples.htl.core.hashmap.Settings"
data-sly-include="${ 'productdetails.html' # requestAttributes=settings.settings}" />
https://docs.adobe.com/content/help/en/experience-manager-htl/using/htl/block-statements.html#request-attributes
There is another way. You can pass additional parameters to the Sling Model on initialization using data-sly-use. For example:
<div data-sly-use.model="${'com.model.Teaser' # test='abc'}"
You can read then the variable "test" in model from request:
#PostConstruct
private void initModel() {
String value = request.getAttribute("test");
// value is 'abc'
}
In order this to work correctly you need to make sure your Sling Model is adaptable from request #Model(adaptables = SlingHttpServletRequest.class}

Extending CQ5 List component

I'm looking into extending the cq5 list component to create custom list displays (obviously). The constructor takes a SlingHttpServletRequest and the minimal java doc says "creates a list from the specified request".
Can someone explain how those request settings are used to build the list? what things in the request should I change to alter the list? Is there better documentation somewhere?
The component uses the request to retrieve the resource object.
In the init method it retrieves a the resource node's properties.
The "listFrom" property should matter for you the most as it controls how the list is created. Either by querybuilder, search, retrieving the children ("children") or tags.
The List component does a simple string equals to find out which option is set and executes the associated logic.
At the end a PageIterator is returned, which is processed by the jsp.

How to get Properties from an EObject, similiar to the Properties View

i have an EObject and want to get all the Properties from it. I tryed to get all Structural Features:
myEObject.eClass().getEAllStructuralFeatures()
but i get too many Properties i do not want like the object ID.
With
myEObject.eClass().getEStructuralFeatures()
there are missing some that are displayed in the Properties View.
So how can i get the same List of Properties from an EObject like the Properties View does?
Thx for your help
Just use the first option and filter out the ones you don't want (like object id) from being displayed. It's probably the easiest way.
If it must absolutely be the same as the list that is displayed in the properties view, the safest bet is to find the code used to populate the properties view and reuse it.

Setting a dependency property's default value at design time in a Windows Workflow Foundation Custom Activity

I'm implementing a Custom Workflow and Activities to be reused in multiple projects and trying to get them to be as easy to use as possible. In this workflow I have a Property whose name is 'UserID' which I'd like to bind to a dependencyproperty in one of my activities. I can currently bind it at design time searching explicitly for the property each time I add one of these activities to the workflow, but I'd like for this activity to be binded automatically.
As far as i know (correct me if I'm wrong), to bind a dependency property at design time I need to specify a string of the form "Activity=NameOfWorkflow, Path=UserID" to the DefaultBindingProperty metadata tag, and I'd like the name of the workflow to be completed in some way. Any way of doing this?
Thanks
I finally managed to achieve this by attaching an ActivityToolboxItem to the Activity, and overriding a method in it that creates the instance shown in the designer. I used an ActivityBind object to bind the dependencyproperty to the workflow's property. To get the instance of the workflow, I just searched for an ancestor to my activity by calling act.Parent until the activity had no parent (and thus was the StateMachineWorkflowActivity itself)