collectiveaccess / providence

Cataloguing and data/media management application
GNU General Public License v3.0
290 stars 166 forks source link

Layered metadata element containers not obeying ''ifdef' display templating #1542

Open Monica-Wood opened 4 months ago

Monica-Wood commented 4 months ago

This might be a tricky one to explain, so I'll do my best.

I have a metadata element that is a container, and within this container there are 2 other containers eg. 'line1', 'line2'. Inside each of the line* containers are the actual metadata elements (in this case a daterange in line1 and text in line2). For clarity I am talking about the 'acqinfo' container that is found in ISAD(G) profile.

When displaying this data using display template (in both providence and pawtucket)

<ifdef code="ca_objects.acqinfo">
    <h6>Acquisition Details</h6>
    <div>
    <ifdef code="ca_objects.acqinfo.acqinfoDate">Date: ^ca_objects.acqinfo.acqinfoDate<br></ifdef>
    ^ca_objects.acqinfo.acqinfoDetail
    </div>
</ifdef>

It will return the 'Acquisition Details' header, even though there is no data in the container.

I edited the database to remove the elements from the intermediate containers 'line1', 'line2' and place them directly under the top container and it started to work as you would expect.

So something is up with the display templating dealing with multi-layered containers.

kehh commented 4 months ago

If you remove the intermediate containers you'll have to also set the correct parent id and I think left and right values as well for child elements for them to play nicely.

kehh commented 4 months ago

rebuild hierarchies for the ca_metadata_elements table if possible

Monica-Wood commented 4 months ago

I don't want to remove the intermediate containers. The issue is about how the display template isn't working as expected when there are intermediate containers. I only removed them so I could test if this was the reason, as containers without them were displaying correctly.

collectiveaccess commented 4 months ago

We will investigate this.

collectiveaccess commented 3 months ago

I don't see a problem here, testing on several production systems using current dev/php8 code. When you using the container code in , as you are, if any part of the container outputs anything, even whitespace, it's going to test true and return template content, including your header. I'd make sure there's nothing in that container that's outputting whitespace, and also consider changing the to test on a specific sub-element.

In my tests I used the container code but made sure all sub-elements (which included text fields, lists and dates, as well as intermediate sub-containers) were entirely devoid of content. In those cases the template was suppressed. Adding white space to the text fields triggered the template, which is how it's supposed to work.

If you want whitespace to be ignored in it would certainly be possible to add that option.

Monica-Wood commented 3 months ago

Definitely no content in it. I delete the container and save so there is nothing showing in that bundle, just the "add acquisition details" plus button. It then doesn't show on the template. BUT it's set to have min of 1 bundle showing, so it pops up again after the save. If you save the record again, not touching that bundle at all, it shows in the template again. It is a container with only 2 other containers. One container holds a date range, the other a text field.
I will test further, but so far it does it on all containers that only have fields in intermediate containers.

collectiveaccess commented 3 months ago

When you output the container itself (^ca_objects.acqinfo), even if all of the constituents are blank you should be seeing semicolons (the default delimiter). The behavior for converting a reference to a container to a string for display in a template is to string together all of the sub-values with the delimiter, which defaults to a semicolon. It's the delimiter between the blank values that is triggering the ... at least that's the most likely thing going on. Setting the delimiter to nothing at all should resolve this. Does the template below work for you?

<ifdef code="ca_objects.acqinfo%delimiter=">
    <h6>Acquisition Details</h6>
    <div>
    <ifdef code="ca_objects.acqinfo.acqinfoDate">Date: ^ca_objects.acqinfo.acqinfoDate<br></ifdef>
    ^ca_objects.acqinfo.acqinfoDetail
    </div>
</ifdef>
Monica-Wood commented 1 week ago

Hi Seth, Just getting back to this issue now. I tried your suggestion and it seems to be working to suppress the output on those nested containers that are empty.