Jump to content

Show field only if repeater matrix field has content


Tyssen
 Share

Recommended Posts

I'm upgrading an old PW site which originally just had a single body field and now giving them a repeater matrix field which will allow more types of content.

For the template, if the repeater matrix field has content I want to hide the old body field from the editor. What would be the conditional that I'd enter into the settings for the body field? I thought it might be something like matrix_content.count=0 but that doesn't work.

Link to comment
Share on other sites

Try in your template:

<?php 
// assuming 'matrix' is the name of your repeater matrix field
if($page->hasField('matrix') && $page->matrix->count > 0) : 
	echo $page->render('matrix');
else:
	echo $page->body;
endif; ?>

 

Link to comment
Share on other sites

Yes, that's what I've already been looking at. What I don't know is what selector to put in the show-if dependencies field. If it was a checkbox it would be checkbox_field=1 but I don't know what the format should be for repeater matrix fields.

Link to comment
Share on other sites

So no way to do it without having to fiddle around with extra fields? It's not that important if the field still shows, so if there's not a simple straight forward to do, I'll leave it as is.

Link to comment
Share on other sites

On 2/28/2024 at 8:52 AM, DV-JF said:

You should be able to do something like this:

This is awesome. Thanks for that contribution and many thanks to the module's author.

On 2/28/2024 at 6:57 PM, Tyssen said:

Thanks @DV-JF that works great! 👍

Maybe you can add [SOLVED] to the post title.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...