# migxLoopCollection output to individual field placeholders?

**URL:** <https://community.modx.com/t/migxloopcollection-output-to-individual-field-placeholders/5014>\
**Category:** Extras\
**Created:** [February 25, 2022, 11:19am UTC](https://community.modx.com/t/migxloopcollection-output-to-individual-field-placeholders/5014 "2022-02-25T11:19:32Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![vibedesign](https://community.modx.com/user_avatar/community.modx.com/vibedesign/32/741_2.png) [@vibedesign](https://community.modx.com/u/vibedesign)\
**Post date:** [February 25, 2022, 11:19am UTC](https://community.modx.com/t/migxloopcollection-output-to-individual-field-placeholders/5014/1 "2022-02-25T11:19:32Z")

</div>

Is there a way to have one `migxLoopCollection` call but output the results by the individual fields in their own placeholders instead of one template chunk?

For example if I have a members TV with fields like `name`, `age`, `phone`, `email`, etc., how can I do something like this:

```auto
[[migxLoopCollection? 
  &packageName=`members` 
  &classname=`Member` 
  &where=`{"id": "[[+memberId]]"}`]]

[[+member.name]]
[[+member.age]]

// instead of:

[[migxLoopCollection? 
  &packageName=`members` 
  &classname=`Member` 
  &tpl=`@CODE:[[+name]]`
  &where=`{"id": "[[+memberId]]"}`]]

[[migxLoopCollection? 
  &packageName=`members` 
  &classname=`Member` 
  &tpl=`@CODE:[[+age]]`
  &where=`{"id": "[[+memberId]]"}`]]

```

I saw there is quite a few [renderOutput - properties](https://github.com/Bruno17/MIGX/wiki/migxLoopCollection) but unfortunately not much of an explanation on how to use them and as some of them are very familiar, I couldn’t figure out if one of the others was doing what I need.

---

<div class="post-metadata">

**Author:** ![halftrainedharry](https://community.modx.com/user_avatar/community.modx.com/halftrainedharry/32/1063_2.png) [@halftrainedharry](https://community.modx.com/u/halftrainedharry)\
**Post date:** [February 25, 2022, 11:42am UTC](https://community.modx.com/t/migxloopcollection-output-to-individual-field-placeholders/5014/2 "2022-02-25T11:42:47Z")

</div>

I believe if you use the property `toPlaceholders`

```auto
[[migxLoopCollection?
      ...
      &toPlaceholders=`member`
]]

```

you should be able to use the placeholders `[[+member.name]]` or `[[+member.age]]`.

---

<div class="post-metadata">

**Author:** ![vibedesign](https://community.modx.com/user_avatar/community.modx.com/vibedesign/32/741_2.png) [@vibedesign](https://community.modx.com/u/vibedesign)\
**Post date:** [February 25, 2022, 3:14pm UTC](https://community.modx.com/t/migxloopcollection-output-to-individual-field-placeholders/5014/3 "2022-02-25T15:14:26Z")

</div>

That seems to work in general, although I have this TV nested inside a regular migx TV `categories` and starting with the second instance of that, the displayed values of the members are wrong, despite the right IDs are getting called for.

```auto
[{
  "caption": "Categories",
  "fields": [{
    "field": "category",
    "caption": "Category"
    },
    {
    "field": "memberlist",
    "caption": "Member",
    "inputTV": "member" // migxdb config tv
    }
  ]
}]

Output:
[[+member.name]] ([[+memberId]])

Category A
- Member Joe (1) // correct
- Member Jane (3) // correct
- Member Tom (7) // correct

Category B
- Member Tom (2) // wrong name, right ID
- Member Tom (5) // wrong name, right ID
- Member Tom (4) // correct

```

Whenever I duplicate a category, all new entry names will be the one from the last entry of the previous category, although if I change the order or remove and add members after that, it will switch up, so I couldn’t find a totally consistent pattern here.

I suspect the placeholders must be interacting with each other across the individual category instances?

---

<div class="post-metadata">

**Author:** ![halftrainedharry](https://community.modx.com/user_avatar/community.modx.com/halftrainedharry/32/1063_2.png) [@halftrainedharry](https://community.modx.com/u/halftrainedharry)\
**Post date:** [February 25, 2022, 4:37pm UTC](https://community.modx.com/t/migxloopcollection-output-to-individual-field-placeholders/5014/4 "2022-02-25T16:37:54Z")

</div>

I’m struggling to understand how exactly you are outputting your data.  
Can you provide this information?

* * *

In my view, it’s probably simpler to create a custom snippet than trying to combine _getImageList_ and  
_migxLoopCollection_ and guessing how they work.

---

<div class="post-metadata">

**Author:** ![bruno17](https://community.modx.com/user_avatar/community.modx.com/bruno17/32/71_2.png) [@bruno17](https://community.modx.com/u/bruno17)\
**Post date:** [February 25, 2022, 6:58pm UTC](https://community.modx.com/t/migxloopcollection-output-to-individual-field-placeholders/5014/5 "2022-02-25T18:58:40Z")

</div>

I think, this has todo, how MODX tags are parsed.  
If a tag is parsed once within a request, the same tag with the same footprint will allways return the same (first) output.

You will need to set different placeholders for each loop within the migxLoopCollection - call. Maybe try `&toPlaceholders=`member[[+id]]` ` and `[[+member[[+id]].name]]`

---

<div class="post-metadata">

**Author:** ![vibedesign](https://community.modx.com/user_avatar/community.modx.com/vibedesign/32/741_2.png) [@vibedesign](https://community.modx.com/u/vibedesign)\
**Post date:** [February 25, 2022, 7:39pm UTC](https://community.modx.com/t/migxloopcollection-output-to-individual-field-placeholders/5014/6 "2022-02-25T19:39:21Z")

</div>

> [@bruno17](#):
>
> I think, this has todo, how MODX tags are parsed.

That’s what I suspected as well.

> [@bruno17](#):
>
> Maybe try `&toPlaceholders=`member[[+id]]` ` and `[[+member[[+id]].name]]`

That’s a great idea, it work but you have to use `[[+idx]]`.

Thanks a lot for all your help!

---

<div class="post-metadata">

**Author:** ![system](https://community.modx.com/user_avatar/community.modx.com/system/32/2_2.png) [@system](https://community.modx.com/u/system)\
**Post date:** [February 28, 2022, 2:30pm UTC](https://community.modx.com/t/migxloopcollection-output-to-individual-field-placeholders/5014/7 "2022-02-28T14:30:05Z")

</div>

Closed on February 28, 2022, 2:30pm UTC

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”.
