valan Posted September 15, 2015 Share Posted September 15, 2015 I have a Page field that stores car pages from cars catalog. Each page is either Make or Model or Modification depending on its place in tree. Currently I use titles for page labels as seen at picture. The problem is that labels may have same title and its hard-to-impossible to understand car page location in tree structure by looking at field. E.g. I need labels that say where in tree structure car page is located, smth like this - for makes: {title} for models: {parent.title} > {title} for modifications: {parent.parent.title} > {parent.title} > {title} How to do that? Link to comment Share on other sites More sharing options...
LostKobrakai Posted September 15, 2015 Share Posted September 15, 2015 https://processwire.com/blog/posts/processwire-2.6.16-core-updates-more-on-prodrafts/#page-fields-now-support-custom-format-labels Does this work for you? Link to comment Share on other sites More sharing options...
valan Posted September 16, 2015 Author Share Posted September 16, 2015 @LostKobrakai - no, it doesn't work for me as currently tags do not support conditions. I need different labels for different templates (or places in tree) - makes/models/modifications. Link to comment Share on other sites More sharing options...
LostKobrakai Posted September 16, 2015 Share Posted September 16, 2015 Sure, somehow I imagined the topmost pages to not have parents anymore xD But the feature is still the right call. The page inputfield is calling Page::getMarkup, which you can simply hook. In the field settings just use insert "MySpecialLabelKey" or whatever string you want to init the hook. $wire->addHookBefore("Page::getMarkup", function($event){ $page = $event->object; $key = $event->arguments(0); if($key == "MySpecialLabelKey"){ if($page->template == "manufacturer") $key = "{title}"; if($page->template == "model") $key = "{parent.title} {title}"; } $event->arguments(0, $key); }); 1 Link to comment Share on other sites More sharing options...
valan Posted September 16, 2015 Author Share Posted September 16, 2015 In the field settings just use insert "MySpecialLabelKey" or whatever string you want to init the hook. I've copied code to admin.php and placed MySpecialLabelKey string to "Custom page label format" but it still doesn't work. Is "Custom page label format" the right place to insert the string? Link to comment Share on other sites More sharing options...
LostKobrakai Posted September 16, 2015 Share Posted September 16, 2015 Should be. I've currently not the time to test this further, but it looked like the inputfield will just pass the string to the getMarkup function. Link to comment Share on other sites More sharing options...
valan Posted September 16, 2015 Author Share Posted September 16, 2015 Yes, this is strange. Looks like hook doesn't trigger... I've added wire()->log->error('Im here!'); at second line but it doesn't log anything. wire()->addHookBefore('Page::getMarkup', function($event) { wire()->log->error('Im here!'); $page = $event->object; $key = $event->arguments(0); if ($page->template != 'service') return; if ($key == 'MySpecialLabelKey') // service_exclude_cars { if($page->template == 'vehicle-make') $key = '{title}'; if($page->template == 'vehicle-modelGroup') $key = '{parent.title} > {title}'; if($page->template == 'vehicle-model') $key = '{parent.title} > {parent.title} > {title}'; } $event->arguments(0, $key); }); Link to comment Share on other sites More sharing options...
LostKobrakai Posted September 16, 2015 Share Posted September 16, 2015 You're on the dev version of pw? Also what's the first if statement doing there? $page is not the page holding the inputfield. It's the page the inputfield is trying to get the label from. Link to comment Share on other sites More sharing options...
valan Posted September 16, 2015 Author Share Posted September 16, 2015 Aaa, ok - you are right re $page. Removed. PW 2.6.17 dev. 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