Answers.Body: <p><code>relation_interview_persons</code> is not an array of elements but an object of type <code>ElementQuery</code>. In order to get the results you need to call <code>one()</code>.</p>
  
  <p>Keep in mind chances are high there is no related element if that's the case your code will throw an exception.</p>
  
  <pre><code>{% set person = object.relation_interview_persons.one() %} {{ person? person.firstname : ''}}
  </code></pre>
  
  <p>If <code>date</code> is not a field of type text but a Date field that will throw an exception as well since it's an object and no string </p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-28T20:41:09.833Z
Answers.Text: Wohee, thanks! I now did `{% set person = object.relation_interview_persons.one() %} {{ person? person.firstname : ''}} {{ person? person.lastname : ''}} ({{date|date("d.m.Y")}})` so also the date is output correctly. I've set all those fields to required.
Answers.UserDisplayName: Urs
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-28T20:41:57.540Z
Answers.Text: So as long as it's on one line, any twig code will work there? (I'm thinking about looping through the last names of all used persons)
Answers.UserDisplayName: Urs
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-28T20:42:52.973Z
Answers.Text: The line number doesn't matter.. You can write what you want since it's treated as an normal Twig template. If you feel like it, you can even update other elements within the template or create fancy queries and such
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-28T14:31:05.160Z
Answers.LastActivityDate: 2018-08-28T14:31:05.160Z
Answers.UserDisplayName: Robin Schambach
Body: <p>I have the following 1:n relation between two sections:</p>
  
  <ul>
  <li>Source Element: Interview </li>
  <li>Target Element: Persons</li>
  </ul>
  
  <p>In the CP (only there) I need to be able to identify Interviews by the name of the interviewed persons. </p>
  
  <p>So in the <code>title format</code> field for the entry type I tried something like</p>
  
  <pre><code>{date}-{relation_interview_persons[0][firstname][lastname]} 
  </code></pre>
  
  <p>But that's no good.</p>
  
  <p>Is that even a valid approach?
  Of course, we can simply use a custom title and that's it.</p>
  
Tags: <templating><control-panel><relations>
Title: CP: Title from relation?
ThreadText: # CP: Title from relation?
  
  (Asked by: username_0 on 2018-08-28)
  
  I have the following 1:n relation between two sections:
  
  * Source Element: Interview
  * Target Element: Persons
  
  In the CP (only there) I need to be able to identify Interviews by the name of the interviewed persons.
  
  So in the `title format` field for the entry type I tried something like
  
  ```
  {date}-{relation_interview_persons[0][firstname][lastname]} 
  
  ```
  
  But that's no good.
  
  Is that even a valid approach?
  Of course, we can simply use a custom title and that's it.
  
  **Tags:** templating, control-panel, relations
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-08-28. Score: 2 | Accepted answer
  
  `relation_interview_persons` is not an array of elements but an object of type `ElementQuery`. In order to get the results you need to call `one()`.
  
  Keep in mind chances are high there is no related element if that's the case your code will throw an exception.
  
  ```
  {% set person = object.relation_interview_persons.one() %} {{ person? person.firstname : ''}}
  
  ```
  
  If `date` is not a field of type text but a Date field that will throw an exception as well since it's an object and no string
  
  > **Comments:**
  > **username_0**: Wohee, thanks! I now did `{% set person = object.relation_interview_persons.one() %} {{ person? person.firstname : ''}} {{ person? person.lastname : ''}} ({{date|date("d.m.Y")}})` so also the date is output correctly. I've set all those fields to required.  
  > **username_0**: So as long as it's on one line, any twig code will work there? (I'm thinking about looping through the last names of all used persons)  
  > **username_1**: The line number doesn't matter.. You can write what you want since it's treated as an normal Twig template. If you feel like it, you can even update other elements within the template or create fancy queries and such  
  
  ---
  
  