pwfans Posted May 9, 2019 Share Posted May 9, 2019 One of my clients site is using textarea field for main information, title field is not necessary to use, so when he use texarea in "List of fields to display in the admin Page List", page tree show multiple line with long text. How to force textarea content to single line ?, just like gmail inbox : subject is auto truncate with menu show up at right side when hovering, it would be supernice if admin tree page list can be done like that. Thanks Link to comment Share on other sites More sharing options...
bernhard Posted May 9, 2019 Share Posted May 9, 2019 I guess you could do a CSS solution: https://www.google.at/search?q=css+truncate+multiline+text&oq=css+truncate&aqs=chrome.1.69i57j0l5.4338j0j4&sourceid=chrome&ie=UTF-8 Or you could also create custom labels via a hook: // /site/ready.php $wire->addHookAfter('Pages::saveReady(template=yourtemplate)', function(HookEvent $event) { $page = $event->arguments(0); $page->yourcustomlabel = $this->sanitizer->truncate($page->yourtextarea, 150); }); 2 Link to comment Share on other sites More sharing options...
pwfans Posted May 10, 2019 Author Share Posted May 10, 2019 @bernhard - CSS solution doesn't go, it will need this module which doesn't work on my side , i already read and do what docs said but css just not loading. - Hook solution work !, i'm blank with coding in hook, is there anyway to auto truncate by detecting template and field? no need to re save the page ? if it's need to work that way, it's ok, it's already much better than default, thanks a lot for this hook solution ?♂️ Link to comment Share on other sites More sharing options...
bernhard Posted May 10, 2019 Share Posted May 10, 2019 4 hours ago, pwfans said: Hook solution work !, i'm blank with coding in hook, is there anyway to auto truncate by detecting template and field? no need to re save the page ? if it's need to work that way, it's ok, it's already much better than default, thanks a lot for this hook solution ?♂️ Don't know what you mean by auto truncate by template/field, but you have all information available in your hook: // /site/ready.php $wire->addHookAfter('Pages::saveReady', function(HookEvent $event) { $page = $event->arguments(0); $page->template; // yourtemplate $page->yourfield; // yourvalue if($page->template == 'foo') $page->bar = 'yournewvalue'; }); You need to save all existing pages. That's easy using TracyDebugger + Console: $pages = $pages->find('yourselector'); $all = $pages->count(); foreach($pages as $i=>$p) { l("saving page $i/$all id $p"); $p->save(); } If you have lots of pages you might run into execution timeouts and need to do that in batches (by appending ",sort=id,id>xxx" to your selector to skip already updated pages. Or you could only select non-updated pages via "yournewfield=" (empty) in your selector. Link to comment Share on other sites More sharing options...
pwfans Posted June 13, 2019 Author Share Posted June 13, 2019 For others need this solution using css, no need to use admin custom file module, just make custom admin css file inside template folder, add path to that css to admin.php inside template folder. Original reference : 1 Link to comment Share on other sites More sharing options...
bernhard Posted June 13, 2019 Share Posted June 13, 2019 Thx for the reminder about admin.php - I'm always creating hooks for injecting custom scripts. admin.php might be easier and a better place ? 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