Jump to content

How to get PageTable pages when not published


alexcapes
 Share

Recommended Posts

I have a PageTable field (editions) that I need to access the top page even if the page is unpublished:

$page->editions[0]->id

This throws up an error when the top page is unpublished, however works fine when it's published.

I know I can't access the pages as children because the PageTable order differs from the child order, and I need the top page as it is in the PageTable field.

Any ideas how I may be able to do this?

Link to comment
Share on other sites

What exact error/exception are you getting? 

I just tried this in one of my installs and it works:

$price = $page->pricebulletin[0]; //unpublished pagetable page
wire('log')->save('dev','price: ' . $price->id);

maybe you're missing something else?

 

  • Like 1
Link to comment
Share on other sites

34 minutes ago, ottogal said:

Do you really need to unpublish the page? Why not just hide it?

It's a valid point - I think I may just have to rethink the workflow and require that editor publishes at least one PageTable page to be able to view the parent page.

Link to comment
Share on other sites

I don't really understand why:

$page->editions->find("include=all")->first()->title;

doesn't work.

I just tested:

$page->editions->find("sort=-sort")->first()->title;

which does work, so I think PageTables are missing the "include" option in the find selector.

Seems like a bug to me - anyone else?

Link to comment
Share on other sites

4 hours ago, ottogal said:

Do you really need to unpublish the page? Why not just hide it?

A PageTable field will not normally output a hidden page either. See here.

But you can use getUnformatted() to get unpublished or hidden pages.

$result = $page->getUnformatted('my_pagetable_field')[0];
//or
$result = $page->getUnformatted('my_pagetable_field')->first();

 

  • Like 4
Link to comment
Share on other sites

12 hours ago, Robin S said:

A PageTable field will not normally output a hidden page either. See here.

But you can use getUnformatted() to get unpublished or hidden pages.


$result = $page->getUnformatted('my_pagetable_field')[0];
//or
$result = $page->getUnformatted('my_pagetable_field')->first();

 

Just to note this works but does not seem to work outputting image fields.

Link to comment
Share on other sites

1 hour ago, alexcapes said:

Just to note this works but does not seem to work outputting image fields.

It works for me - what part isn't working for you?

$result = $page->getUnformatted('my_pagetable_field')->first();
echo $result->my_image_field->first()->url;

 

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.
  • Similar Content

    • By daniel_puehringer
      Hi community,

      I am using the "PageTable" Module (also called "ProFields: Page Table") and the built in "Language" Module (also called "Languages Support").

      With the help of PageTable I was able to create several content elements which should usually be displayed in German(default language) and English.

      However some Content Elements should only be shown in German and NOT in English.

      Well sounds easy, right? Not so fast. I really love this CMS, but I have not found a solution for this problem yet.
      As you can see in the screenshots attached I tried to uncheck the "active" Checkbox for the english language to completely hide the content element for english users.

      However no matter what I do the german text shows on the english page.
      If I leave the "content-should-not-be-shown-in-english"(see Screenshot Number 2) blank and save the page, the page will inherit the german page url "content-element-with-simple-text-which-should-only-be-shown-in-german".

      My question therefore is:
      How can I hide a specific content-element for only one language?

      I´m using the latest processwire & module versions.

      The code which I use to render the content elements looks like this:
      //Info: contentelements is a field of type "ProFields: Page Table" <?php foreach ($page->contentelements as $element): echo($element->render()); endforeach; ?> filename: basic-page.php


      I would really appreciate your help since I haven´t found a solution after reading through quite a lot of forum posts.

      All the best,
      Dani


    • By LAPS
      I opened a new wishlist topic on the PW forum for this and in the meantime I ask to the community looking for a reasonable solution.
       
      Using the PageTable field, is there a way to un-restrict the creation of pages under a given parent template page (or as page children if no parent for items is selected)? That is, is there a way to allow the selection of the parent page dynamically / on the fly during page creation via the PageTable field?
    • By LAPS
      I'm using the PW PageTable field extensively and I think an improvement to it could be made regarding the ability to choose the page parent where the page created via PageTable will reside.
      Say you have a PageTable field set like this:
      Edit Field: page_table_field > Details >
      Select one or more templates for items
      > template_one
      > template_two
      > template_three
      Select a parent for items
      > parent_template
      Actually, you can only create pages under the parent_template page (or as page child if no parent for items is selected).
      BTW I am looking for reasons about this limitation.
      What about allowing to choose on the fly where the pages created via PageTable will reside? that is, having the possibility to choose dynamically under which parent page to create the pages?
      Actually, one could overcome to this by creating multiple appropriately set PageTable fields, one PageTable field per PageTable parent for items, but this is unsustainable (?) when you want to create a lot using PageTable…
      By allowing to choose dynamically / on the fly the parent page during page creation via the PageTable field would open up a wider usage of PageTable.
      What do you think about?
       
      @ryan @Robin S
    • By JeevanisM
      HI,
      The scenario is,  I manage a magazine website, I have an article to publish, but before making it public available, I have to show the preview to my Editor and get approval. What I have done is, I created the page, filled the contents then put it as a Unpublished status. I as admin can see the preview of the page but when I send this page link to the editor ( he has no admin access, he should not because the person may vary with each articles ) , the editor cannot view the preview of Unpublished page. Is there any workaround on this ?  Is it possible to make this preview page watchable with a direct link ?


      thanks
    • By louisstephens
      So I ran into a very strange issue today. I have a template with a pagetable and I went to add an item to it, when I went to select an image (for an image field) the page instantly threw up an error
      "ProcessPageSearchLive: No search specified"
      The page's content also switched to the image attached. This all worked perfectly last week (local mamp box). Has anyone experienced this before, and how did you solve it?
       

×
×
  • Create New...