Jump to content

Admin - show content from a field on another page


sambadave
 Share

Recommended Posts

Hi there

Short version of question

Let's say I have a page in the admin that contains a field... Is it possible to output the content from that field on another page in the admin? Almost like a reference.

Longer version of question (with example)

A house builder with multiple (60+) developments. They want to be able to create notices/messages that can be added to one or many developments. Handy for things like regional covid lockdowns or temporary office closures due to bad weather.

My approach for the admin editing options:

  1. Add each message to each development
    Pros: You edit the message on the development page in context
    Cons: Very time consuming and repetitive if the same message needs to be applied to 60+ developments

     
  2. Control all the messages from one admin page and say which development each message should be applied to
    Pros: Easier to add/remove messages to more than one development at a time. Control all messages from one place.
    Cons: Content is not added on development page, which is where typical admin users may expect to find it

I went for option 2 due to flexibility, and created a page within the admin for global development notices. This contains a repeater with:

  • Field for message to display
  • Checkbox list of all developments. The user can select which ones to apply each message to

It's working really well but the only thing is that if the user goes to a specific development in the admin, the relevant messages aren't displayed in context (as they aren't edited on that page and instead on the global development notices page)... which may cause confusion when a new staff member / content admin tries to edit the text but there is no field when they go to the development admin page where they expect to see it...

Solution???

I don't require the message(s) to also be editable on the development page, but I wondered if there was a nice way to show it/them somehow. I feel like I am missing something really simple as I'm sure ProcessWire will have a nice way of achieving this, or maybe there are field settings that allow this kind of thing to happen?

Any ideas on approaches or similar experiences would be much appreciated, even if it is just a much simpler example with the content from one field being shown on another admin page to get the ball rolling.

Thanks in advance for any advice :)

Link to comment
Share on other sites

There's of course a (simple) solution for your problem:

  1. Create a site with the name "Messages" (I use a template called "options" for this only with a title)
  2. Create a template for the messages e.g. with title and body field.
  3. Create a field "Choose messages" fieldtype "Page Reference"
  4. Setup this field - see:
  5. Add this field to your "development" template
  6. Code 🙂
    foreach($page->messages as $mes) { echo $mes->titel;}

Hopefully this will you - if you have any questions, please don't hesitate to ask 😉

Greets!

 

Edited by DV-JF
typo :-)
  • Like 1
Link to comment
Share on other sites

I know that a runtime field is tempting because it abstracts complexity but such things can quite easily be done via hooks as well. That means you don't need a module and you get even more possibilities:

<?php
$wire->addHookAfter("ProcessPageEdit::buildForm", function($event) {
	$page = $event->object->getPage();
	if($page->template != "mytemplate") return;
  
	$form = $event->return;
	if($f = $form->get("title")) {
		$next = $page->next;
		if($next) $f->notes = "Title of next page: ".$next->title;
	}
});

 

  • Like 2
Link to comment
Share on other sites

Thanks @bernhard I've very little exposure to hooks but I really should have a dig around and this is a great example to work from.

Also thanks @DV-JF I never thought of that approach as well, by addidng pages through the page reference field.

As always, there are lots of great ways to approach it with PW which is great.

I apreciate your help 😀

Link to comment
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
 Share

×
×
  • Create New...