1

I have a field name with a long "Field Label" name and I want the "Short Name" to be consistent also.

But I notice that ExpressionEngine truncates the "Short Name" to a certain length. So it seems that there is a limit to the number of characters one can put in "Short Name".

Is there a way around this?

1 Answer 1

1

You'd need to modify the database. The channel_name field in exp_channels allows up to 40 characters, you could change it match channel_title that allows 100 characters, but I'd recommend not doing so.

My recommendation is mostly based on naming logic, field_names versus the field_label. Field labels are meant to be flexible and of benefit to the user, field names are to aid the current and future developers of your project.

For example, your project may start off with a single channel of data, let's say default. In that channel you might create fields like: summary, description, table of content, keywords, etc.

And that's all great, until you add your second channel, that let's say manages book reviews, and you need the fields summary, review, image, and keywords. Now you have duplicate field names, which can't exist at the database level within the same data table, so you might call summary => short and keywords => tags. By the time you hit the fifth channel, your naming convention is pretty much a mess.

The problem becomes the lack of a naming convention. Naming conventions are helpful to developers, even if you are the only one, let's say you need some quick assistance, it should only take a few moments for a new developer to understand your naming convention. If it takes much longer, it's probably not an ideal convention.

My preferred convention is using the section_name as part of the field_name, so if I have a Book Review section of the website then…

channel => books
template_group => books
field_group => books
fields =>   {book_authors}, {book_summary}, {book_review}, {book_rating}, {book_image}, and {book_notes}

You don't have to do it this way. There have been a few articles by developers talking about how they name and how this can make things in development easier.

But generally speaking, it's not a short_name if it's over 50 characters. Labels can be long and descriptive (but not the actual description, there is a field for that), but short_names should be succinct and convey information. {book_summary} tells me not only that the field will be short, either varchar, tinytext or probable text. But that it's a short, descriptive field, in the field_group for the section called book.

Having fields convey info to other developers is helpful. It removes or at least reduces the need for keeping field_lists available. As a guest developer, maybe providing you 10 minutes of assistance, if your naming convention used section_field, I could easily guess that a news section would be

<div class="news">
<h2><a href="/news/article/{url_title}" title="{title}">{title}</a></h2>
<p>{news_summary}</p>
<p class="attribution">{news_author} for {news_outlet} on {news_date}</p>
</div>

Without having to pull a field list, etc. If, I guess wrong, say {news_outlet} was actual {news_vendor} then that's a quick and easy fix or adjustment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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