How can I set an entry title automatically, based on a related entry? 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?
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.

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.first().title }} - {{ object.userBooking.first().username }}


You need to use the first() 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.first().title} - {userBooking.first().username}