theo

Page Lister more than title possible?

Recommended Posts

Hello

Can I define what the title shows in page lister?

Is it possible to combine the title with other field values or plain text?

E.g Fields are
 

Title: MyProduct

Color: Red

Can Page Lister show "MyProduct (Red)" ?

Or

Title: 22

Can Page Lister show "22 inch" ?

Thank you.

Share this post


Link to post
Share on other sites

Go to "edit template", select tab "advanced" and you'll see a settings section that looks like this:

pagelist.thumb.PNG.63b32d21b184a097a39376ed779f27df.PNG

  • Like 3
  • Thanks 1

Share this post


Link to post
Share on other sites

... unlimited possibilities with a hook ...

5a80cfe791695_Bildschirmfoto2018-02-12um00_20_42.thumb.jpg.09fca441919c09cbf76ea97f48b6f20d.jpg

Code

// ready.php
$wire->addHookAfter('ProcessPageListRender::getPageLabel', function($e) {
	$listedPage = $e->arguments[0];
	// ...
	$e->return = '...';
});

 

  • Like 5
  • Thanks 1

Share this post


Link to post
Share on other sites

Thank you.

Can I have the same for the page title / heading?

pwhead.png.a2ba0f87b093c74d0e70fa3973b58ede.png

I'm sorry for asking stupid questions. Many things are obvious, some things are not. ;)

Share this post


Link to post
Share on other sites
49 minutes ago, theo said:

Can I have the same for the page title / heading?

Of course ...

/**
 * modify headline in page edit interface
 */
$wire->addHookAfter('ProcessPageEdit::headline', function($e) {
    // get id of page beeing edited
    $pid = (int) $this->input->get('id');
    if (!$pid) return;
    $pageBeeingEdited = $this->wire('pages')->get($pid);
    if (!$pageBeeingEdited->id) return;
    $headline = "My ID is $pageBeeingEdited->id";
    $this->wire('processHeadline', $headline);
    // no need to modify the return value ($e->return)
});

 

  • Like 3
  • Thanks 1

Share this post


Link to post
Share on other sites

Thanks Kixe. This works.

I have never used ready.php before. :rolleyes:

Is there a way to use simple HTML in the headline? Like italic, bold etc.

From a quick test, I see that it outputs tags as... tags.

Share this post


Link to post
Share on other sites

Just wanted to explain @kixe's excellent answer a little for those who might be wondering why that hook isn't listed in the Tracy Captain Hook panel or on the Captain Hook page: https://processwire.com/api/hooks/captain-hook/

What is going on is that ProcessPageEdit extends Process and Process has a ___headline() hookable method. 

If you're used the Tracy Captain Hook panel, it always pays to check the class that the current class extends:

 

image.thumb.png.175bcf9da1fbb43922731a4377103da5.png

Now we're looking at the hooks for the Process class and we can see that headline is available.

image.thumb.png.24d4997ec1433bd95bd3b84d41e56f0b.png

 

Hope that helps!

The other useful tip is the to click the "Toggle All" button at the top and CTRL/CMD +F and look for "headline"

  • Like 6

Share this post


Link to post
Share on other sites

One tweak that I think is worth making is to use: $e->object->getPage() rather than $this->input->get('id') to get the page being edited.

/**
 * modify headline in page edit interface
 */
$wire->addHookAfter('ProcessPageEdit::headline', function($e) {
    $pageBeeingEdited = $e->object->getPage();
    if (!$pageBeeingEdited->id) return;
    $headline = "My ID is $pageBeeingEdited->id";
    $this->wire('processHeadline', $headline);
    // no need to modify the return value ($e->return)
});

 

  • Like 2

Share this post


Link to post
Share on other sites

@theo

You can use html, but you'll need to create a new admin theme to accomplish this ... :rolleyes:


If the AdminTheme you are using extends the AdminThemeFramework class (UI-kit) or contains the AdminThemeDefaultHelper class, all tags are entity-encoded.
https://github.com/processwire/processwire/blob/e73ec872da5f9db2960524dbb984287bfe4b7b4e/wire/core/AdminThemeFramework.php#L156

  • Thanks 1

Share this post


Link to post
Share on other sites
7 hours ago, theo said:

Is there a way to use simple HTML in the headline? Like italic, bold etc.

 

It's kinda hacky, but this does work:

$this->addHookAfter('Page::render', function($event) {
    if($this->process != 'ProcessPageEdit') return;
    $p = $this->process->getPage();
    $headline = "My ID is $p->id";
    $event->return = str_replace($p->title.'</h1>', '<strong><em>'.$headline.'</em></strong></h1>', $event->return);
});

 

image.thumb.png.31ef1ae7c702854fabd05417098f1dbb.png

 

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites

Next question. :rolleyes:

Not sure if I should open a new thread for this.

Can I show some "virtual hierarchy" in the backend?

For example my real page hierarchy looks like

P
-Aa
-Ab
..
-Zz

Can I show something like

P
-A
--Aa
--Ab
..
-Z
--Zz

You see the letters of the alphabet, you can "open" them, as if they were pages, but in fact they aren't real pages.
It is just for grouping things better.

I could add real pages for each letter of the alphabet, but I'm not sure if this makes sense.
It deepens the (real) structure with no obvious benefit, other than grouping.

I hope you understand what I mean. I'm completely open to any kind of thoughts regarding this matter.

Thank you.

EDIT: Or sth. similar to paging. Instead of 1 2 3 there would be A B C or some other criteria?

Share this post


Link to post
Share on other sites
On 12/02/2018 at 12:24 AM, kixe said:

... unlimited possibilities with a hook ...

5a80cfe791695_Bildschirmfoto2018-02-12um00_20_42.thumb.jpg.09fca441919c09cbf76ea97f48b6f20d.jpg

 

Hey @kixe thanks for this idea, I tried to implement it but I ran into an issue. I can't manage to set a different label depending on a condition. I think I must be missing something.

 

The hook :

$this->wire->addHookAfter('ProcessPageListRender::getPageLabel', $this, 'getPageLabel');
public function getPageLabel($event) {
		$listedPage = $event->arguments[0];
		if($listedPage->template->name == 'tpl1' || $listedPage->template->name == 'tpl2') {
			$this->status = $this->getUpdateStatus();
			foreach ($this->status as $key => $value) {
				$event->return  = 	($this->status[$key]['closing'] == -1 || $this->status[$key]['transactions'] == -1)
					? '<span class="uk-label label-update-status-error">ERR</span> '
					: '<span class="uk-label label-update-status-ok">OK</span> ';
			}
		}

	}

 

Each page on the page-tree have the same label label-update-status-ok :

label.png.8ff6ae88986ae149ad5c2f5fa2e789ba.png

 

Could you share a portion of code ?  😁

@theo sorry for hijacking your thread 😅

 

 

Edit:  fixed, it was just bad logic in the foreach loop inside the hook.

Thanks again @kixe it rocks !

Edited by flydev
fixed
  • Like 1

Share this post


Link to post
Share on other sites

@adrian

6 hours ago, adrian said:

It's kinda hacky, but this does work:


$this->addHookAfter('Page::render', function($event) {
    if($this->process != 'ProcessPageEdit') return;
    $p = $this->process->getPage();
    $headline = "My ID is $p->id";
    $event->return = str_replace($p->title.'</h1>', '<strong><em>'.$headline.'</em></strong></h1>', $event->return);
});

 

Cool ^-^...
... but you will get unexpected results if the page has no title and uses the name instead or whatever.


I would replace $p->title with $this->wire('processHeadline') to get it more stable.

$this->addHookAfter('Page::render', function($event) {
    if($this->process != 'ProcessPageEdit') return;
    $p = $this->process->getPage();
    $headline = "My ID is $p->id";
    $event->return = str_replace($this->wire('processHeadline').'</h1>', '<strong><em>'.$headline.'</em></strong></h1>', $event->return);
});

 

@flydev

$this->getUpdateStatus() // ? what's that? return?

 

  • Like 1

Share this post


Link to post
Share on other sites

It  just return a multidimensional array where I can check a value (key: 'closing' or 'transactions') and assign a different label.

Share this post


Link to post
Share on other sites
19 minutes ago, adrian said:

Maybe this module from @Robin S can help you achieve what you want"

https://github.com/Toutouwai/VirtualParents

Thank you adrian.

This looks close and interesting, but I don't think it is very practical in my case.

From what I understand reading the description, I would have to make two separate templates for every letter in the alphabet and the virtual parents would have to be real pages anyway.

Am I right?

Thank you.

Share this post


Link to post
Share on other sites
5 hours ago, adrian said:

Maybe this module from @Robin S can help you achieve what you want"

https://github.com/Toutouwai/VirtualParents

5 hours ago, theo said:

This looks close and interesting, but I don't think it is very practical in my case.

Yeah, that module wouldn't really be practical if you need more than one or two virtual parents. The Virtual Parents module was an experiment to answer the question "To what extent is it possible to trick ProcessPageList into showing a page structure that isn't real?" And now that I've tried it I can answer with "To only a very limited extent". ProcessPageList just isn't designed to support anything other than the real page tree and forcing it do otherwise is pretty painful.

There have been several requests for a way to browse an alternative page structure. It will require a module that builds its own tree from scratch and doesn't rely on ProcessPageList. It's on my to-do list but it will be challenging and I'm not sure when I'll get to it. And bear in mind too that any module like this will come with other limitations - for instance, it wouldn't be possible to sort or move pages like ProcessPageList can because the page structure shown might have no resemblance to the real structure.

 

  • Like 2

Share this post


Link to post
Share on other sites

Thank you adrian and Robin S.

Changing the tree hierarchy is probably not the best idea, and it doesn't have to be for my case.

A different idea is, to do it somehow like the pager. Instead of numbers, there could be letters of the alphabet or other categories.

This would be less problematic imho. 

What do you think? 

pwpager.png.c2b2ebda95e3659c511a554d5c23d15b.png

 

Share this post


Link to post
Share on other sites
23 minutes ago, theo said:

A different idea is, to do it somehow like the pager. Instead of numbers, there could be letters of the alphabet or other categories.

As before, you can't easily modify ProcessPageList for this purpose. But you can use Lister (Pages > Find). So in your case you would filter according to some parent or some template, plus filter by "title starts with" some character.

I have a module under development that will allow for a list/tree that dynamically changes the selector used by Lister. Not sure when it will be ready but that might end up being helpful for your scenario.

  • Like 1
  • Thanks 1

Share this post


Link to post
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


  • Recently Browsing   0 members

    No registered users viewing this page.