Sonataadminbundle: Truncated titles

Created on 21 Dec 2017  路  16Comments  路  Source: sonata-project/SonataAdminBundle

Hello,

Is there a reason to truncate titles?

https://github.com/sonata-project/SonataAdminBundle/blob/3.x/src/Resources/views/CRUD/base_show.html.twig#L14-L16

{% block title %}
    {{ "title_show"|trans({'%name%': admin.toString(object)|truncate(15) }, 'SonataAdminBundle') }}
{% endblock %}

I have been requested to display the title as it's provided, however looks like this Twig conditional is not allowing parameters to truncate the title or leave it as it is returned by the __toString magic method.

Could be possible to add a parameter to allow users to keep the title as it's returned by the method?

enhancement

Most helpful comment

But couldn't we truncate it via css?

screenshot 2017-12-21 08 14 00

All 16 comments

I am totally with you and I like this "feature" neither.

@sonata-project/contributors WDYT, shall we change this behavior to show the complete title or make in configurable?

@rande can you remember about this?

You should be able to override the template and change that specific block.

Truncate is there to avoid really long names. I dont think we want more options to change that, if we already have a way to override it.

Truncate is there to avoid really long names.

ok, but 15 chars is very short, maybe we could use 50 or sth like this

It depends. If you have multiple tabs on the admin or you are using lower resolution, You might be needing not a lot of chars there.

But couldn't we truncate it via css?

screenshot 2017-12-21 08 14 00

IMHO @OskarStark 's proposal to truncate it via CSS makes more senes to me

As @jordisala1991 pointed, screen size could be a problem, but we build responsive sites, right? So this truncated copy could be managed via CSS based on the screen resolution.

The title is also used for the browser title, so we should truncate it at the server.

Hey @core23

Why to truncate the browser title? In the end, Sonata Admin provides and admin panel that - by definition - requires a valid login, so SEO and other stuff that could be affected by this is not a problem.

The title is also used for the browser title, so we should truncate it at the server.

why do we have 2 titles then?

https://github.com/sonata-project/SonataAdminBundle/blob/3.x/src/Resources/views/CRUD/base_show.html.twig#L14-L20

Why to truncate the browser title?

Because an entity with a veeeeeerrry long name could destroy the browser title so you only get the entity name in the title and no further information which side you are on.

Hey @core23

Based on W3C title should be okay as far as length is 64 characters:
https://www.w3.org/Provider/Style/TITLE.html

SEO Moz suggests between 50-60 however I guess W3C is more relevant here:
https://moz.com/learn/seo/title-tag

And SEO Quake through their browser extension says up to 70 characters is fine:
_"The most effective page titles are about 10-70 characters long, including spaces."_

I don't think that truncate the title to display just 15 characters is the best here, based on these reports from W3C and SEO Tools, so maybe allow between 50 and 70 could be better.

Thoughts?

Please be aware, that the full title is not cropped to 15 chars. Only the entity name is cropped to 15 chars.

Depending on the locale, the title could be something like:

Show "My cool entity ..."

"My cool entity ..." betrachten

The full title of 50 chars+ would only be visible if you have only one tab open. That's the reason why we have the limit.

Feel free to override this in your project template.

Hi,

Just to confirm, before to close the issue: I just need to extend a new template form the base one and then set it on the project settings, like this?

app/config/config.yml

sonata_admin:
    templates:
        show: ::sonata_show.html.twig

app/Resources/views/sonata_show.html.twig

{% extends 'SonataAdminBundle:CRUD:base_show.html.twig' %}

{% block title %}
    {{ "title_show"|trans({'%name%': admin.toString(object) }, 'SonataAdminBundle') }}
{% endblock %}

I have tested this, but I just want to make sure - from your POV - if I should add any other change that I could be missing.

Thanks,

About that example:

Show "My cool entity ..."
"My cool entity ..." betrachten

Is a potential update to do something like this? [action]: [title] so:

Show: "My cool entity..."
Betrachten: "My cool ..."

In this way we can see always the "action" that we are doing, and we can truncate it at 60 characters:

{{ block('title')|truncate(60) }}

Does this make sense?

I'm closing this issue since #5595 is already closed and released on version 3.50.0.
Thank you!

Was this page helpful?
0 / 5 - 0 ratings