We are transitioning over to a new forum platform. Please post new issues there. Existing threads will be dealt with here unless you choose to move them over. Visit the new forum

Forum

Thread tagged as: Question

How to hide an "image" type field in the control panel?

I'm using the Blog app and have a custom author field which is an image (and is part of the author.html template). When I output that image as part of Blog's post.html template the author image field is undesirably added to the post edit screen in Perch. In other cases I can set the "type" of the custom author field to "hidden" to hide it from the control panel, but in this case it needs to be "image" to use Perch's resizing and cropping.

How can I hide it from the control panel and retain the sizing/cropping of the "image" type?

Perhaps there is a way to include a template for output but NOT include the fields in the control panel?

Kirk Roberts

Kirk Roberts 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

At the top of your template, use the same ID as a type="hidden" field.

Tried that, and it seems that the second (last) use of that ID is dictating the form display. In the below template the "Oh Boy!" tag appears in the edit form, not the "Hello!" tag: [[[ edit: actually, it doesn't matter if the "Hello!" tag is at the top or bottom of the template, or if the other tag attributes are included. ]]]

<perch:blog id="author_image" type="hidden" label="Hello!" />
<div class="author-box main-bg-color alt-text-color clearfix">
        <perch:if exists="author_image">
        <div class="img-wrap">
            <perch:if exists="author_link"><a href="<perch:blog id="author_link" type="hidden" />"></perch:if>
                <img src="<perch:blog id="author_image" type="image" width="91" height="91" crop="true" density="2" label="Oh Boy!" />" class="img-responsive" alt="<perch:template path="blog/author_name.html" rescope="parent" />">
            <perch:if exists="author_link"></a></perch:if>
        </div>
    </perch:if>
    <div class="text">
        <div class="author">
            <perch:if exists="author_link"><a href="<perch:blog id="author_link" type="hidden" />"></perch:if>
            <perch:template path="blog/author_name.html" rescope="parent" />
            <perch:if exists="author_link"></a></perch:if>
        </div>
        <div class="about"> <!-- italic -->
          <perch:blog id="author_biog" type="hidden" html="true" />
        </div>
    </div>
</div>
Drew McLellan

Drew McLellan 2638 points
Perch Support

Hmm, I guess that will happen with images. We can the template for all options and process them all.

I think the solution is probably to use two templates - one for editing and one for display.

Okay, thanks for your insight. Sounds like a decent plan.

As a kludge I'm using a bit of jquery to remove that field in the edit form, fully aware that a future update could break this code.

<script>
    $(function() {
        $('#blog-edit #perch_author_image').closest('.field').remove();
    });
</script>
Drew McLellan

Drew McLellan 2638 points
Perch Support

Please don't do that. The edit forms are far more complex than they might appear, and if you start messing with the fields we can't guarantee that they'll work in the way you expect.

Noted, thanks!