<p>You should be able to use the full Twig tag for what you want to do.  Perhaps something like the following (which assumes you have an <code>email</code> field you are trying to output for each user and want to separate your emails by a comma):</p>

<pre><code>{% for person in object.belongsTo %}{{ person.email }}{% if not loop.last %},{% endif %}{% endfor %}
</code></pre>

<p><code>renderObjectTemplate</code> should parse both the abbreviated syntax with a single curly brace or complete Twig tags.  To take a close look, the abbreviated syntax:</p>

<pre><code>{ belongsTo.first.fullName }
</code></pre>

<p>Is being interpreted by Craft as the following:</p>

<pre><code>{{ object.belongsTo.first.fullName }}
</code></pre>

CC BY-SA 3.0
2014-09-09T18:02:09.570Z
Ben, this would be useful if I needed fullName, or title. However, what I need is an array with UserModels, to use further down the road ...
Paul
CC BY-SA 3.0
2014-09-09T22:10:23.933Z
Not sure I understand the question then @PaulVerheul.  I was assuming the belongsTo field was returning userModels and you were preparing your data to output in your template.  Can you explain why you are using `renderObjectTemplate` and still trying to access the variables it's parsing down the road?  `renderObjectTemplate` renders Twig code, so it can output a Twig tag which is already an array, but it's not going to give you an array back to use later.  Is the array you want already available in your `$entry` variable?
Ben Parizek
CC BY-SA 3.0
2014-09-08T14:49:19.327Z
2014-09-08T18:21:17.907Z
2014-09-08T18:21:17.907Z
Ben Parizek
<p>From my plugin, I know I can use ...</p>

<pre><code>craft()-&gt;templates-&gt;renderObjectTemplate($string, $entry)
</code></pre>

<p>... to parse, for example, { belongsTo.first.fullName } to the full name of the first user in the belongsTo field.</p>

<p>Now, I need an easy way to parse { belongsTo.find } into an array with all users related to this belongsTo field. Is there an easy way to do this, or should I let my plugin do the work?</p>

<p><strong>Background information</strong></p>

<p>My custom notification plugin has a settings field where I can set the 'receivers' of a notification. If an entry has a user field called 'belongsTo', and the setting is { belongsTo.find }, I need all the users related to this field, so I can further process the notification.</p>

<plugin-development><templating>
How can I 'Parse' { entry.belongsTo } to array with users?
# How can I 'Parse' { entry.belongsTo } to array with users?

(Asked by: username_0 on 2014-09-08)

From my plugin, I know I can use ...
craft()->templates->renderObjectTemplate($string, $entry)

... to parse, for example, { belongsTo.first.fullName } to the full name of the first user in the belongsTo field.
Now, I need an easy way to parse { belongsTo.find } into an array with all users related to this belongsTo field. Is there an easy way to do this, or should I let my plugin do the work?
Background information
My custom notification plugin has a settings field where I can set the 'receivers' of a notification. If an entry has a user field called 'belongsTo', and the setting is { belongsTo.find }, I need all the users related to this field, so I can further process the notification.

**Tags:** plugin-development, templating

---

## 1 answers

### Answer by username_1 on 2014-09-08. Score: 2

You should be able to use the full Twig tag for what you want to do.  Perhaps something like the following (which assumes you have an email field you are trying to output for each user and want to separate your emails by a comma):
{% for person in object.belongsTo %}{{ person.email }}{% if not loop.last %},{% endif %}{% endfor %}

renderObjectTemplate should parse both the abbreviated syntax with a single curly brace or complete Twig tags.  To take a close look, the abbreviated syntax:
{ belongsTo.first.fullName }

Is being interpreted by Craft as the following:
{{ object.belongsTo.first.fullName }}

> **Comments:**
> **username_0**: Ben, this would be useful if I needed fullName, or title. However, what I need is an array with UserModels, to use further down the road ...  
> **username_1**: Not sure I understand the question then @PaulVerheul.  I was assuming the belongsTo field was returning userModels and you were preparing your data to output in your template.  Can you explain why you are using `renderObjectTemplate` and still trying to access the variables it's parsing down the road?  `renderObjectTemplate` renders Twig code, so it can output a Twig tag which is already an array, but it's not going to give you an array back to use later.  Is the array you want already available in your `$entry` variable?  

---

