Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7996239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:39:38+00:00 2026-06-04T14:39:38+00:00

I want to have display-only fields to render data that’s never going to be

  • 0

I want to have display-only fields to render data that’s never going to be changed nor submitted.

Similar to bootstrap’s static controls.

I need to show object data within a form without breaking the form structure or style. I want this data to use the same templates as all other inputs, but without rendering it as a dynamic input.

I thought of several ways to achieve this, some are plain hacks, some others seem more legitimate, but I wan’t to know if there is a more standard way to do this.

Here’s the list of options I have thought of in no particular order:

  1. Use the read only property for fields: it does not feel very nice, I don’t want users to feel they can change something, but they are not allowed for some reason.

  2. Hack the templates to output something other than input elements: seems very nasty to me, besides it would be necessary to handle server side the the missing fields on submits.

  3. Extending field types to create display-only versions of them. I don’t think this would be safe.

  4. Writing a custom fieldType to do the job. This option would be good to use as a base type for other fields.

I think the best solution is either option 3 or 4.
The only thing I still haven’t found is how to handle the missing fields on submit.

I think it’s important to have this type of fields because it allows reusing form types logic. Otherwise I end up writing twig templates that look like this:

<form>

    {# This is the average writtable field #}
    {{ form_row(form.field1) }} 

    {# This is the display-only field, notice I have to replicate
       markup. Even if I wrote a macro, which I did, I would still
       have to replicate markup in the macro.
    #}
    <label>Field 2</label>
    <div>{{ the_object.field2 }}</div>

</form>

And finally, does anyone have a better idea or think that this approach is flawed altogether?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T14:39:39+00:00Added an answer on June 4, 2026 at 2:39 pm

    I finally used the read_only property and custom templates (a combination of options 1 and 2) to change the rendering of fields with the read_only property on.

    Fields with the readonly property on are not expected to be sent (they are rendered with the disabled attribute, the same @elnur pointed out) and are rejected if present on POST, so all I had to do is change the templates to render differently.

    Here is an example template:

    {% block field_widget %}
    {% spaceless %}
        {% if read_only %}
            <span {{ block('widget_container_attributes') }} >
                {{ value|default('&nbsp')|raw }}
            </span>
        {% else %}
            {% set type = type|default('text') %}
            <input type="{{ type }}" {{ block('widget_attributes') }} value="{{ value }}" />
        {% endif %}
    {% endspaceless %}
    {% endblock field_widget %}
    

    Another way to do it would be using form extensions to create a new property for all fields, but the read_only property suit my needs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables and I want to display only the child ID that
I have some text/images that I only want to display in the normal state
I have a partial that I want to display in a layout only when
I want to display only children categories of a particular category. Suppose I have
I want to have a element that displays in the multiple selection display style
I have multiple SharePoint lists and want to display data from them on to
I have several unordered lists that I want to display like this: <ul> <li><img></li>
I have the following situation where I want to only display the search results
I want my search to only display results that match values in the same
want to have a Hyperlink-Button in a gridView in which I can display a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.