adinuno Posted September 19, 2013 Share Posted September 19, 2013 Hi there, I've got two templates that need some of the same fields. So, is it possible to get a field value from another template? So when I update on one template, I update on all other fetching this field? Thanks Link to comment Share on other sites More sharing options...
kongondo Posted September 19, 2013 Share Posted September 19, 2013 I think I get what you are saying but not entirely. Data is not stored on a template basis but on a page basis. Yes, fields are associated with the templates in which they appear but ultimately, data stored is unique for each page using that template. By updating one template, do you mean update one page? You can also set some fields as Global (e..g the title field in the default install) but I don't know if that helps in this case. Using the API and hooks you can definitely update some fields automatically depending on some other fields. I believe I have seen such an example here in the forums...But, again, I am not sure I follow your question 1 Link to comment Share on other sites More sharing options...
BFD Calendar Posted September 25, 2013 Share Posted September 25, 2013 I have a likely question, in a quite practical manner. Say I have a list of names that includes a John Smith where every name has a page with some general information and one or more pictures. And I have a list of events that happened to all the people in my list of names, when they were born, when they got their drivers license, when they got married, etc... After I added maybe 32 pages or more about John Smith I find out that his last name is not Smith but Smit. Instead of searching for all event pages relating to John Smith and changing his name to Smit it would be easy to just update the one page about John Smith in my list of names and have all other pages with stuff that happened to John Smith get his name from there and thus get updated automatically. Link to comment Share on other sites More sharing options...
ryan Posted September 29, 2013 Share Posted September 29, 2013 What you are talking about is relational data, and you definitely would not want to draw these relations by searching for the person's name (after all, there might be two John Smith's too). You want to use the Page reference field type, which lets you reference one page from another. Create a field called "people", and choose "Page" as the field type. On the "input" tab, choose "person" as the template to use for pages (or whatever you've called your template for people), and asmSelect (or Checkboxes or Page Autocomplete) as the Input type. Save. Add your new field to your "event" template. Edit an event, and now you can select the people that are related to the event. If you later change the person's name or anything like that, then it doesn't matter. To list the people connected with an event, you'd just do this in your code: foreach($page->people as $person) { echo "<p><a href='$person->url'>$person->title</a></p>"; } Link to comment Share on other sites More sharing options...
adinuno Posted October 4, 2013 Author Share Posted October 4, 2013 @kongondo My idea is based on a field's information basis. As if I change field A on a template, it should also change on field A in another template. Is this possible? (sorry for the long delay, but for some unknown reason I wasn't notified of your contributions, even though I have e-mail notifications on ) Link to comment Share on other sites More sharing options...
ryan Posted October 12, 2013 Share Posted October 12, 2013 @kongondo My idea is based on a field's information basis. As if I change field A on a template, it should also change on field A in another template. Is this possible? It seems like you might be asking the same question that's already been answered? Either that or I don't understand the question. I'll step back and assume that maybe you aren't talking about page relations. A best practice would be to make sure you aren't duplicating any data. Meaning, pull the data from the source. For instance, if you wanted to retrieve the first image from the homepage, regardless of what page you were actually on in your site, then retrieve the homepage and pull the value from it. Same goes for anything else. Every page and its data is accessible to you from the API. $homepage = $pages->get('/'); $image = $homepage->images->first(); 1 Link to comment Share on other sites More sharing options...
BFD Calendar Posted October 12, 2013 Share Posted October 12, 2013 What you are talking about is relational data, and you definitely would not want to draw these relations by searching for the person's name (after all, there might be two John Smith's too). You want to use the Page reference field type, which lets you reference one page from another. Create a field called "people", and choose "Page" as the field type. On the "input" tab, choose "person" as the template to use for pages (or whatever you've called your template for people), and asmSelect (or Checkboxes or Page Autocomplete) as the Input type. Save. Add your new field to your "event" template. Edit an event, and now you can select the people that are related to the event. If you later change the person's name or anything like that, then it doesn't matter. To list the people connected with an event, you'd just do this in your code: foreach($page->people as $person) { echo "<p><a href='$person->url'>$person->title</a></p>"; } Actually I want to use different fields from the 'people' template in a text field on the 'events' template. The 'people' template has beside 'firstname', 'lastname' also 'profession', 'alias',.... fields that are sometimes used and sometimes not. They will be used when 'event' text is 'Explorer David Livingstone meets explorer John Stanley' but not when '(victim of Albert DeSalvo) Mary Sullivan is strangled by (Serial Killer) Albert DeSalvo aka The Boston Strangler'. Perhaps using a combination of the Page reference field and the Hanna Code module might do the trick? 'Event' in these examples should get field info from three different pages, two from the 'names' template (A meets B) and one from the 'places' template. To make it even more complex, it would be ideal if 'profession' is called from a template 'professions'. It wouldn't be necessary to have duplicate fields for every explorer or serial killer in the 'people' pages, and easier to produce a list of all explorers or even all events involving explorers. Ahum, just trying to get the most out of PW.... Link to comment Share on other sites More sharing options...
BFD Calendar Posted October 19, 2013 Share Posted October 19, 2013 I solved it like this http://processwire.com/talk/topic/4615-categorisation-vs-relation/#entry46406 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