Turamon Posted June 24 Share Posted June 24 Hi, I am opening an new topic since I did not find something related here. If it has been discussed already, I would be grateful for a link or hint. My use case is the following. I have a poi template for pages which are placed in the page tree under a certain parent page. I also have a page reference template with a page reference referring to pages with this template. Now, when a page based on the poi template is accessed via a page reference in the front end by the user, I would like to - detect that is was called via the specific page reference, and - get the id of the parent page of this page reference. In the php code of the poi template, I would like to react correspondingly, depending on if it was called directly or as page reference and depending on the actual parent of the page reference. Is this possible? Or is there another way to get a similar result? Thank you so much Turamon Link to comment Share on other sites More sharing options...
wbmnfktr Posted June 24 Share Posted June 24 I have read this 10 or more times now and I am still not sure if my understanding is correct, so therefore the following is a bit of a deep-dive here: You have pages around in your site, that are somewhat special beneath/below other pages or at least need to be treated like they are special/or somewhat. I imagine it like something like this: Spain ... France Eiffel Tower (this is the special one) Germany ... And now you need to know if this... referring page (France) is referring to Eiffel Tower or/and the referring page (France) was accessed and you need to know this in the referred page. see below... Case 1: When you are in need to know if a page or any page uses a reference (PageReference field) to point to a specific page (Paris -> Eiffel Tower), there is a selector for that. <?php namespace ProcessWire; // find pages that reference to a POI by POI-field // field: this_is_a_poi = page reference field to select POI pages // used in that template of target page (Eiffel Tower in this case) $who_links_to_me = $pages->findMany("this_is_a_poi=$page, parent=$page->parent") You could put that into place for your POI pages to see what other pages reference it. Case 2: Oh... and there is this $page->links() method in which you can find out which (HTML) field links to that one specific page. Case 3: In case you want to track access to referring pages we first of all need to know what kind of tracking you use, but at least PageHitCounter could be triggered via JS in case a referring page was accessed. Sure there is a bit more needed for this, but I don't know if this is the case, and won't look for a solution that deep. Sorry. ? My understanding for this: poi = POI = Point of Interest And yes... every snippet is untested. Oh... and btw. ... Welcome to the ProcessWire Forums with your first post. Link to comment Share on other sites More sharing options...
Robin S Posted June 25 Share Posted June 25 If you are doing something like this... // Get poi page from Page Reference field $poi_page = $page->my_page_reference_field; // Render poi page echo $poi_page->render(); ...then you can pass variables to the template file of the poi page via the $options array argument. See docs: https://processwire.com/api/ref/page-render/render-page/ // Get poi page from Page Reference field $poi_page = $page->my_page_reference_field; // Render poi page echo $poi_page->render(['rendered_from' => $page]); And in the poi template file: if(!empty($options['rendered_from'])) { $rendered_from = $options['rendered_from']; //... } You can also use the $options['pageStack'] value in the template file. It's mentioned in the docs page linked to above, but probably easiest to understand if you just dump it and see what it contains. 4 Link to comment Share on other sites More sharing options...
Turamon Posted June 26 Author Share Posted June 26 wbmnfktr and Robin s, thank you so much for your suggestions and hints, they will help me do work this out! 2 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