Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using modifiers in title_format #1210

Closed
Paperweb opened this issue Aug 19, 2024 · 3 comments
Closed

Using modifiers in title_format #1210

Paperweb opened this issue Aug 19, 2024 · 3 comments

Comments

@Paperweb
Copy link

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
Copy link

andjsch commented Aug 19, 2024

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
Copy link
Author

Paperweb commented Aug 20, 2024

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 🙏 👏

@duncanmcclean
Copy link
Member

duncanmcclean commented Aug 20, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants