Answers.Body: <p>If you are on an entry page have you tried:</p>
  
  <p>{{ entry.eventBooking.title }}</p>
  
  <p>Because at the moment it doesn't look like your telling craft to look at the eventBooking handle on the entry but the title on a eventBooking variable</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-07T16:02:25.823Z
Answers.Text: I understand what you're saying and it makes sense, but no I still just get "-"
Answers.UserDisplayName: darylknight
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-07T16:14:52.057Z
Answers.Text: You may need to specify the .first() related entry. {{entry.eventBooking.first().title}}
Answers.UserDisplayName: Tyler Willingham
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-07T15:55:11.917Z
Answers.LastActivityDate: 2014-08-07T15:55:11.917Z
Answers.UserDisplayName: Alec Ritson
Answers.Body: <p>I believe this is in regards to the <code>Title Format</code> feature, so just to be explicit in what I'm referring to, Craft Documentation calls this a <a href="http://buildwithcraft.com/docs/sections-and-entries#dynamic-entry-titles" rel="nofollow noreferrer">Dynamic Entry Title</a>.</p>
  <p>The syntax you are looking for can take two forms:</p>
  <p><strong>1) Long form object syntax</strong></p>
  <p>Just as on the front end your <code>entry</code> is available via the <code>{{ entry }}</code> variable, within your Title pattern on the back end, the current entry is available via the <code>{{ object }}</code> variable.</p>
  <p>So I believe the following should work, assuming you are using the actual field names:</p>
  <pre><code>{{ object.eventBooking.one().title }} - {{ object.userBooking.one().username }}
  </code></pre>
  <p>You need to use the <code>one()</code> method here because Relations fields return an array by default. Since you need to output your content directly, you need to make sure you are accessing the <code>title</code> and <code>username</code> properties via the Model they are associated with in that array.  If your fields are required, you can safely assume that the first item will exist in the array.</p>
  <p><strong>2) Short hand syntax</strong></p>
  <p>If what you are doing is simple, Craft gives you the option to make the syntax a bit easier and omit the <code>object</code> variable.  So the above could also be written with single curly braces as such:</p>
  <pre><code>{eventBooking.one().title} - {userBooking.one().username}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-08T08:45:49.623Z
Answers.Text: That shorthand syntax works perfectly, thank you!
Answers.UserDisplayName: darylknight
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-12-15T07:05:53.523Z
Answers.Text: This no longer seems to be working, as of Craft 4. Instead, `{fieldName.one().title}` is working for me.
Answers.UserDisplayName: tremby
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-12-15T18:35:38.173Z
Answers.Text: Good note. That changed a while ago. I updated the answer to reflect the .one() syntax.
Answers.UserDisplayName: Ben Parizek
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2014-08-07T16:33:41.587Z
Answers.LastActivityDate: 2023-12-15T18:35:09.077Z
Answers.LastEditDate: 2023-12-15T18:35:09.077Z
Answers.UserDisplayName: Ben Parizek
Body: <p>If a booking channel contains two Entries fields (one related to a single User, one related to a single 'Event'), how can I get the booking entry title to be set automatically to the following syntax:</p>
  
  <p>"Event Date - Username"</p>
  
  <p>I've set up the entry to not show the title field, but my syntax is wrong. I'm using:</p>
  
  <pre><code>{{eventBooking.title}} - {{userBooking.username}}
  </code></pre>
  
  <p>but all I'm getting is "-", so it's obviously not recognising the fields. Is this possible?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-08-07T16:08:34.893Z
Comments.Text: Are you actually trying to set an entry's title or are you trying to display a title on a page as a combination of those values?
Comments.UserDisplayName: Tyler Willingham
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-08-08T08:47:09.753Z
Comments.Text: I was trying to set the entry's title based on those values when the entry gets created. This has been answered by Ben now below.
Comments.UserDisplayName: darylknight
Tags: <entries><titles>
Title: How can I set an entry title automatically, based on a related entry?
ThreadText: # How can I set an entry title automatically, based on a related entry?
  
  (Asked by: username_0 on 2014-08-07)
  
  If a booking channel contains two Entries fields (one related to a single User, one related to a single 'Event'), how can I get the booking entry title to be set automatically to the following syntax:
  
  "Event Date - Username"
  
  I've set up the entry to not show the title field, but my syntax is wrong. I'm using:
  
  ```
  {{eventBooking.title}} - {{userBooking.username}}
  
  ```
  
  but all I'm getting is "-", so it's obviously not recognising the fields. Is this possible?
  
  **Tags:** entries, titles
  
  > **Comments:**
  > **username_1**: Are you actually trying to set an entry's title or are you trying to display a title on a page as a combination of those values?  
  > **username_0**: I was trying to set the entry's title based on those values when the entry gets created. This has been answered by Ben now below.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_3 on 2014-08-07. Score: 6 | Accepted answer
  
  I believe this is in regards to the `Title Format` feature, so just to be explicit in what I'm referring to, Craft Documentation calls this a [Dynamic Entry Title](http://buildwithcraft.com/docs/sections-and-entries#dynamic-entry-titles).
  
  The syntax you are looking for can take two forms:
  
  **1) Long form object syntax**
  
  Just as on the front end your `entry` is available via the `{{ entry }}` variable, within your Title pattern on the back end, the current entry is available via the `{{ object }}` variable.
  
  So I believe the following should work, assuming you are using the actual field names:
  
  ```
  {{ object.eventBooking.one().title }} - {{ object.userBooking.one().username }}
  
  ```
  
  You need to use the `one()` method here because Relations fields return an array by default. Since you need to output your content directly, you need to make sure you are accessing the `title` and `username` properties via the Model they are associated with in that array. If your fields are required, you can safely assume that the first item will exist in the array.
  
  **2) Short hand syntax**
  
  If what you are doing is simple, Craft gives you the option to make the syntax a bit easier and omit the `object` variable. So the above could also be written with single curly braces as such:
  
  ```
  {eventBooking.one().title} - {userBooking.one().username}
  
  ```
  
  > **Comments:**
  > **username_0**: That shorthand syntax works perfectly, thank you!  
  > **username_4**: This no longer seems to be working, as of Craft 4. Instead, `{fieldName.one().title}` is working for me.  
  > **username_3**: Good note. That changed a while ago. I updated the answer to reflect the .one() syntax.  
  
  ---
  
  ### Answer by username_2 on 2014-08-07. Score: 0
  
  If you are on an entry page have you tried:
  
  {{ entry.eventBooking.title }}
  
  Because at the moment it doesn't look like your telling craft to look at the eventBooking handle on the entry but the title on a eventBooking variable
  
  > **Comments:**
  > **username_0**: I understand what you're saying and it makes sense, but no I still just get "-"  
  > **username_1**: You may need to specify the .first() related entry. {{entry.eventBooking.first().title}}  
  
  ---
  
  