Forum

Thread tagged as: Problem

Content create fields on initial creation

Hello,

I have a question regarding content create, we have used this in the master pages templates so when a user creates a page it creates the region and its properties and then output the fields. This works fine, the user goes into the regions and all is as it should. The only issue we found with this was if we wanted a region for file upload but if no file is uploaded it falls back to some text stating no file has been uploaded.

So the code is like this:

<perch:if exists="report"> 
        <a href="<perch:content id="report" type="file" label="Annual report PDF" />">Download my file</a>
    <perch:else />
        No file uploaded
</perch:if>

The issue comes into play when the user doesn't go into that region when they create the page, which they are unlikely to do unless they need to upload a file when the page is first made, however the template is not rendered, it returns nothing unless they actually go into the region and saves a empty region.

I am not sure if this is just a limitation we need to work with or I am using it in wrong way.

The code for the page is:

    <?php perch_content_create('File Upload', array(
        'template' => 'file.html',
    )); 
    ?>
    <?php perch_content('File Upload'); ?>

Any help would be appreciated.

Bob Gentle

Bob Gentle 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Does it make a difference if your use perch_content_custom() instead of perch_content() ?

No sadly not, I did think it would since I am aware that custom content is not cached in the same way, but alas still nothing is rendered.

Drew McLellan

Drew McLellan 2638 points
Perch Support

A <perch:noresults> section might work in that circumstance.

Will have try to see if that will solve the issue, not sure if helps but having a quick check in the database (and forgive me for my lack of database knowledge here) but in perch2_content_regions the regionHTML has <!-- Undefined content: File Upload --> but if I do go into the region and save (with no file uploaded) this is then populated with No file uploaded. But will have a play with the no results to see what happens.

Drew, just tried the noresults, and it worked! Yay. Thank you very much.