Jump to content
sambadave

Admin - show content from a field on another page

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 :)

Share this post


Link to post
Share on other sites
10 minutes ago, sambadave said:

Solution???

@kongondo's FieldtypeRuntimeMarkup can do exactly that. You just need to add a snippet of code to retrieve and output the relevant messages.

  • Like 2

Share this post


Link to post
Share on other sites
Posted (edited)

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

Share this post


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

Share this post


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

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.

  • Similar Content

    • By humanafterall
      Hi,
      I would like to set an admin template to 'https only' as recommended in the Processwire security docs.
      However if I do this it forces this setting locally too, resulting in https://localhost requests which result in an error page.
      Is there a simple way round this? Setting https for templates in the config?
      Thanks!
    • By daniel_puehringer
      Hi community, thanks for the great work you do 🙂

      I´m looking for a global field which can be used in the footer and has only one instance for all pages. So I´m kind of looking for "One field to rule them all".
       
      Reason for my question: The website I´m currently building has one footer for all pages. The content of the footer should be dynamic - therefore I made a global field which is automatically inserted into each page.
      Problem: if I want to change something in the footer, I have to do it for all fields, because each field has it´s own instance.

      Question: is it possible to have one global field in which changes the content for the footer of all pages?

      In most CMS Systems a simple solution to this is often impossible, I hope that processwire is different 🙂

      All the best,
      Daniel
       
    • By DanielKit
      Hi. I'm currently stuck at the login page in my project. Once I enter my admin username and my password and press login, nothing happens. The page just reloads. However, the URL changes from http://myipaddress/processwire to http://myipaddress/processwire/?login=1. I've checked all of my server settings, and to my knowledge, all seems to be fine there. I don't know where to go from here.. Thanks in advance!
    • By modifiedcontent
      Small annoyance: I get a horizontal scrollbar in UIkit admin area - or actually Admin Theme Boss based on Uikit 3. I tried to fix it with CSS, but had trouble isolating/targeting it and don't want to mess with module or core files. I think this issue has been reported before. Is there a recommended fix? 
    • By codevark
      The Minimal Site works fine, but if I try to login as admin, I have no idea what the credentials are.
      I did not do the "install" process myself. The OVA came with everything set up, but there's no mention of the PW admin credentials being set to some initial value.
      Wondering if anyone else has tried the Bitnami OVA and if there's a simple answer.
      --Pete
×
×
  • Create New...