Jump to content

[solved] $files->render only works on frontend when logged-in


psy
 Share

Recommended Posts

I'm familiar with $files->render and use it reguarly to include snippets in templates, passing PW vars to the snippet file.

Came across a head-scratcher today. In my included snippet, I pass a PW WireArray as a var.

I tried lots of variations in various browsers, all with the same result:

  1. When logged in as admin and viewing page, everything displays correctly
  2. When not logged in, ie guest user, only the included snippet HTML wrapper displayed on the frontend, not the output logic generated within the snippet

The page has no viewing restrictions and the file permissions on the server all look good.

Using: 
ProcessWire 3.0.234
PHP 8.1

Suggestions on how to fix or pointers to the documentation I may have missed, welcome.

TIA
psy

Solution:

The $files->render call was a red herring.

The problem arose with my $pages->find selector. The requested page template is quite complex with a page reference field within a repeater and the parent page hidden from lists and searches. Seems PW struggled with all the complexities involving the repeater field filtering on a page reference field, especially when the page's parent was hidden, and user permissions. In one variation, the selector returned all the correct page ids as a string, despite not specifying same in the selector.

Finally got it to work by making life easier for PW, ie:

<?php
$currency = 'USD';

$things = $pages->find("template=thing, page_thing_type.id=1040"); // get all the published pages with a template of 'thing' and page reference field id of 1040
$things->filter("rptr_currency_and_msrp.page_currency.title=$currency" ); // reduce the PageArray based on the repeater field's page reference field's title
$thingItems = $page->getMythings($things, $currency); // do stuff with the filtered PageArray in a page class

$files->render('inc/my_things',['lines' => $thingItems]);?>

Now all displaying correctly for guest users and tested in multiple browsers.

Edited by psy
solved
Link to comment
Share on other sites

  • psy changed the title to $files->render only works on frontend when logged-in
  • psy changed the title to [solved] $files->render only works on frontend when logged-in

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.
×
×
  • Create New...