Jump to content
alexcapes

How to get PageTable pages when not published

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?

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

It's just not outputting anything for me.

echo $page->editions[0]->id;

This outputs nothing.  However if I publish one PageTable page, it correctly echos the ID.

Share this post


Link to post
Share on other sites

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

  • Like 1

Share this post


Link to post
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.

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites
12 minutes ago, adrian said:

Seems like a bug to me - anyone else?

Keep in mind that the find() in your example is only in-memory filtering. It cannot find additional pages.

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
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;

 

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 jonatan
      Hi! 😄
      SITE SETUP / DESCRIPTION:
      What? Online art magazine with an "All featured works" and also an "All featured artists" index page, and also individual "Work" and "Artists" pages, and data relations between the different artists and their artworks.
      So, I have two different page reference fields, connected by @Robin S's awesome Connect Page Fields module (though that has nothing to do with the issue in fact, Robin's plugin works great! and the issue is the same with or without it).
      The two Page Reference type fields are called "works" and "artists". They are meant to simply connect different artists to different artworks.
      Fx:
      Work 1  (page)  –> artists (Page Reference field) : Artist A (page)           --->>> (automatically connected)         Artist A (page)  –> works (Page Reference field) : Work 1 (page)
      Work 2  (page) –> artists (Page Reference field) : Artist B  (page)           --->>> (automatically connected)         Artist B (page)  –> works (Page Reference field) : Work 2 (page)
      ISSUE:
      On both Page Reference fields, both on "artists" and on "works" this option "Allow unpublished pages" is activated:

      As it says in the option description, supposedly, unpublished pages should be selectable in the page reference field, but they should not be visible, they shouldn't appear, on the front-end...
      Frontend:
      To show all works related to the artist on the artist individual page I'm doing this:
      <?php foreach($page->works as $item) { echo "<img src='{$item->image->first->width(200)->url}' class='pr-2'><a class='pr-4' href='$item->url'>$item->title</a>"; } The problem is now, unexpectedly, if some work is set to "Unpublished", it shows up anyways!
      WORKAROUND:
      So to get around this I figured out that I can do this:
      <?php foreach($page->works as $item) { if($item->is(Page::statusUnpublished)) { return; }; echo "<img src='{$item->image->first->width(200)->url}' class='pr-2'><a class='pr-4' href='$item->url'>$item->title</a>"; } But ofc this is a rather inelegant "solution" which shouldn't really be necessary, right? 
      I might be missing something basic here, but really can't figure out what it is... I hope one of you awesome guys can help me out 😊
      Thanks a lot in advance!
      All the best,
      Jonatan
    • By louisstephens
      So I reread my first draft, and it made absolutely no sense (I deleted it to hopefully better explain myself).  I am trying to make a system (that to me is a bit complicated) utilizing jquery and processwire together. My whole goal is to put a url like https://domain.com/launch?first_name=jim&occupation=builder in a script tag on another site(just a localhost .php page) to then pull out the data for that person and append to divs etc. Basically, the initial script tag would point to "launch" which has a content-type of "application/javascript". Using jquery, I would pull out the persons name and occupation and then make a specific ajax get request to "domain.com/api" (in json format) for a look up of the person. Essentially then I could pull that particular person's information from the json data, and do with it how I please in the "launch" page.  In processwire, I have a page structure like:
      People -Jim Bob (template: person ) --Occupations (template: basic-page) ---Builder (template: occupation) ---Greeter (template: occupation) It is really just a bunch of people with their occupations and a few fields to the occupation template. With the "api" (template: api) url, I was hoping to return all the data (of people) in json format like:
      Example Format:
      { "id": 1, "title": "Jim Bob", "occupations": { "builder": { "id": 44, "title": "Builder", "years_worked": 1, "etc": "ect", }, "Greeter": { "id": 44, "title": "Greeter", "years_worked": 1, "etc": "ect", }, } } Where I get lost is really outputting the page names and nesting in the occupations into json. I have used Pages2JSON before, but I was a bit lost on how to implement what i was thinking.
       
      I have access to all the local host files, but I was hoping to kind of build out a "system" where I could place the script tag/parameters in any project, and be able to interact with the data without doing an ajax call on the actual site. In a way, this would keep processwire handling all the data and requests, and my other "projects" just with a simple script tag. This might all be way too much/over complicated, but I couldn't quite wrap my head around how to achieve it. 
    • By tron1000
      Hello! I use PW 3.0.98 and I have frontend editing enabled for a PageTable Field. Somehow, when I double click the field in the frontend, the iframe in wich the content is displayed is very small (see screenshot). I couldn't find out if thats some CSS conflict or another problem. Any suggestions? Thanks, Andrej
       

    • By Noel Boss
      I use a PageTable field to make edits to children of pages more intuitive…
      To register the hooks, insert the following Snippet inside your init function in your module (or add it to your init.php file):
      /** * Initialize the module. * * ProcessWire calls this when the module is loaded. For 'autoload' modules, this will be called * when ProcessWire's API is ready. As a result, this is a good place to attach hooks. */ public function init() { // Prefill pageTable field $this->wire()->addHookBefore('InputfieldPageTable::render', $this, 'addChildrenToPageTableFieldsHook'); $this->wire()->addHookBefore('InputfieldPageTableAjax::checkAjax', $this, 'addChildrenToPageTableFieldsHook'); } Then, add this hook method:
      /** * Fill pagetable fields with children before editing…. * * @param HookEvent $event */ public function addChildrenToPageTableFieldsHook(HookEvent $event) { $field = $event->object; // on ajax, the first hook has no fieldname if (!$field->name) { return; } // get the edited backend page $editID = $this->wire('input')->get->int('id'); if (!$editID && $this->wire('process') instanceof WirePageEditor) { $editID = $this->wire('process')->getPage()->id; } $page = wire('pages')->get($editID); // disable output formating – without this, the ajax request will not populate the field $page->of(false); // you could also insert a check to only do this with sepcific field names… // $page->set($field->name, $page->children('template=DesiredTemplate')); // just specific templates $page->set($field->name, $page->children); } Now whenever there is a page-table field on your page, it gets populated with the children
    • By rareyush
      I am using module "FormTemplateProcessor" to get data in a pages but they all are unpublished and when I am trying to display them with relevent pages it not working
       
      page1 p1 p2 p3 page2 (FormTemplateProcessor) up1 (unpublished page and have p1 id on field knows as "ID") up2 (unpublished page and have p3 id on field knows as "ID") up3 (unpublished page and have p2 id on field knows as "ID") now here
      up1, ip2, up3 can be created by p1, p2 or p3 and I am saving respectively I'm saving their id in field which is being used by up1,up2,up3, etc template.
       
      now I want to show the data from unpublished pages which belongs to p1, p2 and p3 respectively
       
       
      anyone has experienced this or knows something which can help me out ?
×
×
  • Create New...