Lance O. Posted February 3, 2022 Share Posted February 3, 2022 I'm having issues with using markup regions and including field templates. I'm using a PageTable field to add "stacks" to a page. For example, I'm including this in my _main.php file: echo "<main id='main' data-pw-id='content'></main>"; And this in my home.php template: echo "<div data-pw-id='content'>"; echo $page->render('stacks'); echo "</div>"; My fields/stacks.php field template looks like this: <?php namespace ProcessWire; if (wireCount($value)) { echo "<div class='stacks'>"; foreach ($value as $stack) { if (!$stack->isHidden()) { echo $stack->render("fields/stacks/{$stack->template}.php"); } } echo "</div>"; // stacks } Then the code for each stack is located in separate field template files like this: fields/stacks/stack-intro.php fields/stacks/stack-events.php fields/stacks/stack-spread.php fields/stacks/stack-promo.php Unfortunately this approach is not rendering the stack field templates. I'm wondering if the echo $stack->render("fields/stacks/{$stack->template}.php"); line is causing issues? When I comment that line out and just replace it with a simple echo, the markup region works correctly. Debugging shows the following errors, although I'm not sure how to interpret this: Link to comment Share on other sites More sharing options...
elabx Posted February 3, 2022 Share Posted February 3, 2022 I think that since $stack is a Page the valid parameter for render() is a field name and not a path. You might be better of doing something like this: <?php namespace ProcessWire; if (wireCount($value)) { echo "<div class='stacks'>"; foreach ($value as $stack) { if (!$stack->isHidden()) { echo wireRenderFile("fields/stacks/{$stack->template}", ['stack' => $stack]); } } echo "</div>"; // stacks } Just adapt the array, passes as a second parameter to wireRenderFile to be named according to the variables in "stack-{$template}.php" 3 1 Link to comment Share on other sites More sharing options...
Lance O. Posted February 3, 2022 Author Share Posted February 3, 2022 @elabx Fantastic, this solved the problem! Thank you so much! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now