Tyssen Posted February 28 Share Posted February 28 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 More sharing options...
psy Posted February 28 Share Posted February 28 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 More sharing options...
Tyssen Posted February 28 Author Share Posted February 28 That would be on the front end. I was talking about the field settings so that the old field doesn't show in the admin if the new field has content. Link to comment Share on other sites More sharing options...
DV-JF Posted February 28 Share Posted February 28 You could try https://processwire.com/docs/fields/dependencies/ Link to comment Share on other sites More sharing options...
Tyssen Posted February 28 Author Share Posted February 28 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 More sharing options...
Gideon So Posted February 28 Share Posted February 28 Hi @DV-JF Unfortunately, count is not a field. You cannot use your_reapeater.count in the showif setting. Gideon Link to comment Share on other sites More sharing options...
Gideon So Posted February 28 Share Posted February 28 Hi @Tyssen You can add a hidden field to the template and then update the field whenever the page is saved by using a saveReady hook. Then you can use this field in the showif setting. Gideon Link to comment Share on other sites More sharing options...
Tyssen Posted February 28 Author Share Posted February 28 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 More sharing options...
DV-JF Posted February 28 Share Posted February 28 @Gideon So Sorry I posted the wrong link, meant this one: https://github.com/Toutouwai/CustomInputfieldDependencies @Tyssen You should be able to do something like this: 2 1 Link to comment Share on other sites More sharing options...
Tyssen Posted February 28 Author Share Posted February 28 Thanks @DV-JF that works great! ? Link to comment Share on other sites More sharing options...
HakeshDigital Posted March 2 Share Posted March 2 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now