markus_blue_tomato Posted July 9, 2019 Share Posted July 9, 2019 Hi, Do anyone know how to show only a field, if the page is published? I tried `status=published` but this did not work. The field keep invisible also when the page is published. Link to comment Share on other sites More sharing options...
Ivan Gretsky Posted July 9, 2019 Share Posted July 9, 2019 I am not sure I quite understand your problem. But maybe this API reference can help? If not, feel free to explain yourself a little better?. Source code would be the best. Link to comment Share on other sites More sharing options...
horst Posted July 9, 2019 Share Posted July 9, 2019 @Markus (Blue Tomato) the showIf only works with fields and there values. AFAIK, the published / unpublished value cannot be used as condition for showIf directly in the template editor. But you may define a hook and set the visibility of that field within the hook. Here is example code as a starting point. You can use this in site/ready.php $wire->addHookAfter('ProcessPageEdit::buildForm', function (HookEvent $event) { // make sure we're editing a page and not a user if($event->process != 'ProcessPageEdit') return; // get page and form $page = $event->object->getPage(); $form = $event->return; // optionally check for matching template(s) with a condition if('mydesiredtemplatename' != $page->template->name) return; // get the field and conditionally set the visibility $form->get('yourfieldname')->collapsed = $page->isUnpublished() ? Inputfield::collapsedHidden : Inputfield::collapsedNo; $event->return = $form; return; } 5 1 Link to comment Share on other sites More sharing options...
markus_blue_tomato Posted July 10, 2019 Author Share Posted July 10, 2019 ok, thank you for the clearification ? 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