Take the 2-minute tour ×
Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. It's 100% free, no registration required.

I've got a Quick Post widget for notes (tweet-like posts). Is there any way to make the titles optional? I've tried adding the id as an auto-generated title but it doesn't appear to work?

Update: It actually appears that the auto-generated title is now working (thanks to carlcs) but it only works through the entries menu item rather than the quick post widget despite the widget's type being correct.

share|improve this question

2 Answers 2

up vote 3 down vote accepted

If you set the title format to a string like "Note" in the channel's field layout, all your entries will be given this exact name. The entry slug will be saved prefixed: "note-1", "note-2", etc.

If you don't want them all to be named the same, you could add a date to it:

Note {{ 'now'|date('Y-m-d') }}

This approach has one problem, if you make an edit to the "Notes" entry at a later point, the title will get updated to a new 'now' date. To work against that you can add a conditional to the code, checking if a title is already saved for that entry:

{{ object.title ? object.title : 'Note ' ~ 'now'|date('Y-m-d') }}

In the case you add more than one "Note" a day the entries would still be named the same though. To solve that, you could format 'now' to add a time to the title |date('Y-m-d H:i'), or you could use a counter instead. Because entry IDs are saved across all sections you wouldn't want to use them here.

But what you could do is to use the entry title of the previous entry in your "Notes" section (sorted by title) and modify upon that. Just name your first entry in your section "Note 001" and then use this snippet as the title format:

{{ object.title ? object.title : 'Note %03d'|format(craft.entries.type('note').order('title').last().title|slice(5) + 1) }}
share|improve this answer
    
This appears to be a great answer but I can't seem to get it to work. My notes entry type is 3, so I've tried: Note ({{ now|date('Y-m-d') }} - {{ craft.entries.type(3).order(id).last().id + 1 }}) but think I'm going wrong somewhere? –  Shane Hudson Aug 18 at 18:26
    
@shane see my edit. What doesn't work for you? Is nothing added to the "Note" string or what happens? And why are you using entry types for it? Is this notes mixed with other (blog) entries or are you trying to get by with a personal license? –  carlcs Aug 18 at 18:39
    
It does not all me to save when I try to write the note. Yes it is mixed with other entries as Brandon said I would be fine with just the personal license. –  Shane Hudson Aug 18 at 18:40
    
@shane there was a typo in my syntax. –  carlcs Aug 18 at 18:54
    
Note ({{ 'now'|date('Y-m-d') }} - {{ craft.entries.type('3').order('id').last().id + 1 }})should work. but it still isn't tested that well and even my last edit has the same problems as using 'now' has when you make edits to the entry :( damn... –  carlcs Aug 18 at 18:56

So odd, I actually just arrived at this. It was from using the Guest Entries plugin and I wanted a front end form that created a derived title.

My solution was to create a hidden input with the title value as dummy content.

<input type="hidden" name="title" value="placer" />

When the Entry Service ran, it saved the entry with the correct derived title

share|improve this answer
    
I have tried this by manually adding the input field to the DOM. It does work, which would indicate a bug with the quick post widget. –  Shane Hudson Aug 19 at 22:18
    
Actually I was wrong, it seems in this case it does not cause the post to auto generate the title, it just uses 'placer' as the title. –  Shane Hudson Aug 20 at 0:51
    
And you have generate title selected for the section? Odd, it works for me with front end forms. –  Peter Tell Aug 20 at 1:00
    
Peter, what do you mean with "correct derived title"? What does it look like? –  carlcs Aug 22 at 7:08
    
So, I've set up my Entry Type with Show Title Fields unchecked and I've input the following in Title Format: {text1} [{dateCreated|date("M d, Y")}]. Then on my front end form I didn't have a title field because it was derived. However, Craft's validation was kicking in causing the form not to submit. The solution was to put a placer title field. Instead of using the value of that when the form was submitted, Craft correctly used my derived title as described above. –  Peter Tell Aug 22 at 12:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.