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

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...