Jump to content
berechar

Page Field => bidirectional

Recommended Posts

Hello everyone,

I'm currently linking several templates to each other thanks to the Page Field.

Whenever I link a Page (A) to another Page (B), I can only see/edit/remove this relationship at Page A, but not on Page B.

Is it possible to also create/see/edit/remove this relationship from Page B? Thus, having a bidirectional Page Field?

Hopefully this is possible, it would be of major help in the administation workflow.

Greetings,

Charlie

Share this post


Link to post
Share on other sites

If you want to see page A on page B you can install the Page References Tab module. This adds another tab in your page showing which pages are linked.

  • Like 2

Share this post


Link to post
Share on other sites

@berechar,

Not possible out of the box, you need to build a module for that.

The good thing is I have a gist that does bidirectional save / remove for 2 pagefields and 2 templates.

You have to change the hard coded values in that gist or B) write a proper configurable module for that.

(Code a module for this? someone? me not having much time, sorry  )

  • Like 4

Share this post


Link to post
Share on other sites

Hm! That's quite nice! Unfortunately it doesn't enable creation of new links...

Ideally you would need a field which is shared between templates...

Share this post


Link to post
Share on other sites

What is the reason you need this? If it's for the admin and it would be handy to be able to add links on either page A or B then that makes sense. However if you only need it in a frontend template there are other ways to find what page B is linked to without the need for having the field in both templates.

EDIT: Martijn's code looks like it would do what you want though :)

Share this post


Link to post
Share on other sites

What is the reason you need this? If it's for the admin and it would be handy to be able to add links on either page A or B then that makes sense. However if you only need it in a frontend template there are other ways to find what page B is linked to without the need for having the field in both templates.

EDIT: Martijn's code looks like it would do what you want though :)

Yes, it's for the admin. This might become a summer project :-)

  • Like 2

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 celfred
      Hello,
      I'm struggling with this : a 'group' field of 'Page' type.
      The parent of selectable pages is '/groups', the template is 'group', and a member can create some groups in the /groups tree. I would like this user to see only the groups he or she has created so in my 'Find selector' in the backend, I would like to use :

      template=group, created_users_id=$user->id But that doesn't seem to work... I still get the list of all available groups in the /groups tree.
      Any idea ?
      I had a feeling I had already seen that before (something like $user->id must be replaced by users_id or something, but I can't find anything in the Forums... and all my tests keep failing...
    • By louisstephens
      So, I really don't know where to begin with this. I have the thought in my head (the basics), but not really sure how to set it up.
      The desired effect:
      The homepage is set up with a foreach loop that outputs all the child pages (basically just a bunch of pages with pdfs, docs etc stored in a file field). When A user is actually logged in, they can "star" an item or drag and drop (using Dragula) the page to a sidebar. Also, they would be able to reorder the pages in the sidebar.
      The question(s):
      I guess I have multiple questions regarding how to achieve this.
      Would it be best to create a page field in the user template to save the page(s)? How would you actually save the page state (sidebar output, reordering, etc) once the drag and drop has been used? Thanks in advance for any help! A lot of this was just what was in my head, so it might not make full sense. However, I will update this if I can actually wrap my head around everything.
    • By Vigilante
      I'm wondering about creating a query that involves looking across two different parent page trees.
      One parent is for blog posts and it has each post under that.
      Another parent is used for categories and subcategories for the blog.
      Then in the blogs there is a page field that can reference the categories. This is all pretty normal setup so far.
      I created a navigation that lists the current category and its children, but I want to not show categories that have no posts. For some reason I'm drawing a blank.
      So let's say a user clicks category1, and it shows a blog listing for that category. I query for all the child categories of the current one. Now I want to exclude any categories where NO blogs exist that make reference to the category (an unused category). How do I do this in a way that is performant? I don't want to have to query the blogs tree over and over to test for the presence of each category in the list!
      Here is the tree:
      blogs
       - article1  [pagefieldcat = "cat1"]
       - article2 [pagefieldcat = ""]
      categories
      - cat1
      - cat2
      Now when I get all children of categories, I want to exclude cat2 since it's not referenced from any blogs. Can I do this without having to loop and query every category against every blog one by one?
      Thanks
    • By Michael Steinmann
      Hello everyone,
      i guess my php knowledge is not good enough to find a solution for the following problem:
      I'm building a website where i have projects. Each project has tags like "webdesign, responsive, cms, print, flyer" etc. At the end of a project i want to recommend other projects, which have similar tags. I want to limit the recommendations to three other projects sorted by the hightest amount of same tags.
      This is how far i got:
      I'm using
      <?php $interessantes = $pages->find("tags=$page->tags, id!=$page->id"); ?> to find other projects with the same tags, excluding the page i'm already on.
      Then i'm using three foreach-functions to go through the projects i found, the tags they have and compare them with the tags of the project i'm looking at. If i have two identical tags, i count up a variable.
      <?php // Projects i have found foreach($interessantes as $interessant): $i = 0; // Tags of the projects i have found foreach($interessant->tags as $tag): // Tags of the project i'm looking at foreach($page->tags as $tagreferenz): if($tag == $tagreferenz): $i++; endif; endforeach; endforeach; endforeach; ?> You can see what it looks like in the screenshot with a bit of HTML. I marked the tags of the current project green and the identical tags of other projects red with the amount of hits below. So in this example i would want to have three projects with three similar tags and get rid of those with only two and one.

      I guess i have to put my pages into an array (with the number of hits?), sort them and echo them with "limit=3"? Unfortunately i have no idea how to do this. You probably have an even better/shorter solution. Links to other topics are welcome to and i'll try to get my head around it.
      If you need further explanation, i'll try my best.
      Best regards
    • By alxndre
      I'm trying to sort pages based on their parent's fields, which are page references.
      For instance:
      $someOrders = $pages->find("template=order, sort=parent.customer.id"); Here, order's parent has a template called 'orderslip' that has multiple 'order' children. Orderslip contains a page field called customer, and I want to sort based on the parent's customer's id. But i can't make it work. It throws out an exception:
      Error: Exception: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'customer' in 'order clause' (in /srv/rewwwards/wire/core/PageFinder.php line 410) I'm sure customer page field exists and it works everywhere else. It's just that this time, I'm trying to sort it from a page's 'parent' selector. Is it even possible do this?
      As always, any help is greatly appreciated.  Thanks.
×
×
  • Create New...