Jump to content
SwimToWin

Exception: Page is not currently viewable when using $page->children('include=all') and role cannot page-edit

Recommended Posts

I have a nested page structure that fails for users without superuser permissions:

Works for superusers / non-superusers:
    - foo
    -- bar
    --- page (status: published)
    ---- page (status: published)
    --- page (status: published)

Fails for non-superusers (Works for superusers):
    - foo
    -- bar
    --- page (status: published)
    ---- page (status: published)
    --- page (status: unpublished <- apparently the template structure fails when there's one unpublished page)

Template:

    <?php foreach ($page->children('include=all') as $p): #Fails for non-superusers ?>
        <?=$p->render()?>
    <?php endforeach; ?>

    a) Works for non-superusers when I grant Page Edit permissions (on the template) to their assigned role/s.

    b) When I remove 'include=all' or 'include=unpublished' then it also works for non-superusers:

    <?php foreach ($page->children() as $p): #Works for non-superusers ?>
        <?=$p->render()?>
    <?php endforeach; ?>

Error message (non-superusers)
    Internal Server Error
        The server encountered an internal error or misconfiguration and was unable to complete your request.
        Error has been logged.

    /www/site/assets/logs/errors.txt
        /foo/bar/baz/    Error:     Exception: Page '/foo/bar/baz/quz/' is not currently viewable.

    /www/site/assets/logs/exceptions.txt
        /foo/bar/baz/    Page '/foo/bar/baz/quz/' is not currently viewable. (in /wire/modules/PageRender.module line 410)

Debug (non-superusers)

    Error: Exception: Page '/foo/bar/baz/quz/' is not currently viewable. (in wire/modules/PageRender.module line 410)

    #0 wire/core/Wire.php (397): PageRender->___renderPage(Object(HookEvent))
    #1 wire/core/WireHooks.php (823): Wire->_callMethod('___renderPage', Array)
    #2 wire/core/Wire.php (465): WireHooks->runHooks(Object(PageRender), 'renderPage', Array)
    #3 wire/core/WireHooks.php (924): Wire->__call('renderPage', Array)
    #4 wire/core/Wire.php (465): WireHooks->runHooks(Object(Page), 'render', Array)
    #5 site/templates/template.php (191): Wire->__call('render', Array)

 

Share this post


Link to post
Share on other sites
// 'include=all' includes access restricted pages, check access via function viewable() before using render()
foreach ($page->children('include=all') as $p) {
    if ($p->viewable()) $p->render();
}

// without argument (selector) access restricted pages are excluded by default
foreach ($page->children() as $p) {
    $p->render();
}

Why do you want to render multiple pages?

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
      "Permission “page-sort” for template “ ... ” not allowed (requires “page-edit” permission)"

      – This lovely error message is thrown at me, if, as implied by it, I try to add (to my "editor" role) the permission "page-sort" for a specific template, without the permission "page-edit" enabled for the same template.
      Seems like it's been mentioned a few times before but never properly answered, by e.g. @Robin S ... :  
      "Allow the granting of page-sort permission independent of page-edit": https://github.com/processwire/processwire-requests/issues/29
       
       
       


      Why do I wanna do this?:

      I have a page tree structure  🌳  as so:

      ________________________

      Category [C1]
      – Page a [C1_p] – Page b [C1_p] Different category [C2]
      – Page c [C2_p] – Page d [C2_p] ________________________

      The page "Category" has the page-template "C1",
      the pages "Page a" and "Page b" both have the page-template "C1_p".
      The page "Different category" has the page-template "C2"
      the pages "Page c" and "Page d" both have the page-template "C2_p".
       
      The two pages called "Category" and "Different category" do not have any content, they only serve as containers for pages belonging to that category.
       
      I want my "editor" role not to be able to do anything at all with these pages "Category" and "Different category"; i.e. I do not want my editor to be able to edit, move, unpublish, hide, lock, delete (or do anything else to) these category pages. 
      – So, I want my "editor" role to have the "page-edit" permission for pages with the templates "C1_p" and "C2_p", but not for the pages with the category templates "C1" and "C2",
      Also, I want my "editor" role to be able to move the pages with the templates "C1_p" and "C2_p" within their parent-pages. 


      Problem:

      But if I just simply add the "page-edit" and the "page-move" permissions for the "C1_p" and "C2_p" templates, then, using the "editor" role, I am not able to move these "C1_p" (and "C2_p") -template-based pages. I can actually click "MOVE" next to them and then move them, but... then I will be met by the error message "You do not have permission to sort pages using this parent - /Category/".  
      – So, I try to add the "page-sort" (description: "permission to sort child pages") permission to the "C1" and "C2" templates... but then trying to do so I am met by the initially mentioned error message   ! Permission “page-sort” for template “C1” not allowed (requires “page-edit” permission)  . 
      And, as mentioned, I do not want my editor role users to be able to edit these category ("C1" and "C2") pages...
      – what to do about this? 😅 
       
      All the best,
      Jonatan 
    • By FireWire
      Hey all. I'm having an issue with the new custom page classes feature which is a fantastic tool.
      I am running into a recursion issue when attempting to call a custom page class. I have a class called BlogPostPage.php (for blog-post.php) which contains a method called getSummary(). That method gets a summary field or truncates the body in it's absence. I've attached photos of the template code, custom page class code (which I've simplified for testing), and the PW output error.
      There is no recursion in the getSummary() method. This error occurs whether I output multiple blog posts in a loop or if I output one blog post with no looping in my template code.

      In use:
      ProcessWire 3.0.164 dev
      PHP 7.3.13

      I am also using the Template Engine Twig module which has not caused any errors or issues thus far.
      Many thanks!



    • By neonwired
      I'm hoping someone has seen this before. There doesn't appear to be an issue with the user info.

       

    • By EyeDentify
      Hello Dear PW Gurus.

      Hope you fair well in these Corona Crisis times.

      Anyhow, i have a problem with a Cryptic error message that shows up when i am trying to Delete images out of a Images field.
      The Error message does say a little but it does not make sense to me why i can´t delete the images because of it.

      Is it some permission issue perhaps?

      I will attach screenshots of it and what i did prior to it.
      I am from sweden so ignore the funny words here and there.

      Hope you all can send me on the right track.
      i am running PW 3.0.139 on this install.

      Step1:

      Step 2: Select the images with the trashcan symbol

       
      Step 3: Cryptic Error message

      I am scratching my head on this one, have not seen this before.

      Thankfull for all help.
      /EyeDentify
    • By VeiJari
      Hello forum. I'm trying to figure out how to detect if current form has errors after saving it in pw admin page. This is so that our event location isn't added in database if we detect errors. But I can't seem to find a correct way to detect errors? I only found the wire()->errors() and it always triggers even if I don't have any errors. 
      How can I detect errors in a form?
      By error I mean $page->error('this is the red error');
×
×
  • Create New...