Jump to content

Display "Related Data" From Page Field In An Admin Page


Gazley
 Share

Recommended Posts

Hi there,

This question has possibly been asked and answered but I couldn't seem to find a related topic.

I have a Template (Template1) that contains a number of fields, one of which is a Page field. I have an Admin Access page based on this template and data is entered into the page based on Template1.

When the Page field is set on this page, it obviously relates to a different page/template (Template2) that likewise contains its own data. This is the real gist of the question:

After I select a page in the Page field on Template1, how can I have displayed, a piece of "Read Only" data from Template2, adjacent to the Page field in Template1. It's really like I want to create a "custom" read-only field in the template that responds to the settings of the other fields in the template, in this case, a Page field.

Obviously, this would be trivial if I was generating output markup based on Template1. However, Template1 is behind an Admin page that is used for data-entry and I want to show data from the page referenced by the Page field for "information" purposes, solely to help the person who is inputting data.

The second part of this question is that the Page field in Template1 is actually in a Repeater Matrix that is a specified field in Template1. I'm sure that the technique would be similar irrespective of whether the Page field is directly in a Template or inside a repeater in a Template.

Hope this makes sense! I look forward to any suggestions you may have :)

Link to comment
Share on other sites

I seem to recall something similar but can't find it now. You could consider using the module RuntimeMarkup using some custom JS to monitor select changes or if you don't want it to detect live changes just to display the output you want on save. Your PHP code could even reside in a file that you could access using WireRender(). It (the output) wouldn't really be 'adjacent' to your Page Field though :-)

Edited by kongondo
  • Like 2
Link to comment
Share on other sites

@LostKobrakai - that sounds about right. I've used hooks in the past (infrequently) but I've no clue how to create a custom field. Do you have any suggestions as to where I can acquire this knowledge? Any tutorials or sample code that you're aware of? Many thanks!

@kongondo - thanks for the pointers. The ProcessPageEdit::buildForm suggested by @LostKobrakai sounds like it will work but I'll definitely look at your suggestions too.

Link to comment
Share on other sites

It could be as simple as having code like this in your RuntimeMarkup field settings for template 1

//pseudo code
$out = 'No value entered';
if($page->name_of_single_page_field->title == 'whatever') {
    $out = $pages->get('/some-page/, template=template-2')->title;
}
return $out;

If you have further questions let's take it at the module's support forum

Edited by kongondo
  • Like 1
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...