statamic / ideas

💡Discussions on ideas and feature requests for Statamic
https://statamic.dev
32 stars 1 forks source link

Using modifiers in title_format #1210

Closed Paperweb closed 3 months ago

Paperweb commented 3 months ago

Hi there,

I'm a new user of Statamic, and really enjoy it so far. Thanks for this awesome tool !

Issue

I tried to use a modifier in my title_format, like so :

{ first_name } { last_name | truncate(1, '.') }

and it doesn't seem to be parsed properly, as i get :

John { last_name | truncate(1, '.') }

Is that a lack of feature, or a bug ?

Generally, i find that using logic and operators in title_format could be useful.

Thank you !

PW

andjsch commented 3 months ago

Hey! A GH issue is not the right place for support requests. Please head over to the discord or to the GH discussions.

Other than that: Looks like you aren't using double curly braces. Try this: {{ first_name }} {{ last_name | truncate(1, '.') }} Also, check out the at modifier: {{ last_name | at:0 }}

Sometimes, there's also some weird whitespace added by editors. Try removing the spaces between the curly braces like so {{first_name}}. You can readd them after that.

Docs: https://statamic.dev/modifiers/truncate Antlers templating in general: https://statamic.dev/antlers

Paperweb commented 3 months ago

Thank you ! Adding another couple mustaches did the trick. It's strange, because i thought i tried that. Sorry for the derangement.

The docs should maybe be updated with double braces.

I'll remember the Discord for other similar issues.

Cheers !


EDIT :

I even got to make work exactly what i wanted, which is to add the last name's initial only when the first name is also someone else's (which is specified with an homonym toggle field in the collection entry blueprint) :

{{ first_name }} {{ homonym ?= ( last_name | truncate(2, ".") ) }}

Statamic is awesome :pray: :clap:

duncanmcclean commented 3 months ago

Glad to hear you managed to get it sorted! Feel free to contribute to the docs if you feel it could be made clearer.