Jump to content

[SOLVED] Field template output removed from final template output?


BrendonKoz
 Share

Recommended Posts

I'm having a strange issue that hopefully some more seasoned PW users would have some insight on. I have enabled the Functions API, Markup Regions, and am appending a primary template file (of which I currently only have one markup region defined). All secondary major page template files insert their content into that markup region. In one particular page template file, I am attempting to render a field template ("callout.php") if it has content. For whatever reason, it is not rendering. If I insert a <?php die(); ?> within the field template, the output from the template is visible. If I move that <?php die(); ?> statement to outside the IF/ELSE block that tests whether the field has a value, the content from the field's template is no longer rendered. Oddly enough, the RepeaterMatrix field's template immediately preceeding this particular field's template is rendered.

Within /site/templates/policy.php, the following excerpt (for the callout field) is the troublesome code.

<?php namespace Processwire; ?>
[...]
<section class="main-content" id="content-skip">
  <h1><?= page()->title; ?></h1>
  <span class="policy-status">Last updated: Month, Year</span>
  <section class="policy-document">
    <?= page()->render('content_body'); ?>
  </section>
  <?php
    if (page()->callout) {
    	page()->render('callout');
    }
  ?>
</section>

Within /site/templates/fields/callout.php I have the following:

<?php namespace Processwire; ?>
<div class="card border-<?= $value->callout_type->value; ?> mb-3 card-note">
  <div class="card-header"></div>
  <div class="card-body">
    <div class="card-text"><?= $value->content; ?></div>
  </div>
</div>

Regardless of whether the variables are correct or not (based on the die() statements, they are), I would expect the HTML to be rendered. Like stated, if I place a <?php die(); ?> statement inside (at the end) of the callout.php template file, I can see the expected PHP/HTML get output. If I instead place it after the IF statement in the policy.php template file, the HTML output from the callout.php file does not exist.

I'm not sure if it's my mixing of output methods during implementation, or something else entirely. I tried passing an $options array value to prevent caching through page()->render('callout', ['allowCache' => false]); to see if it would make a difference. It did not.

Link to comment
Share on other sites

After your suggestion (thank you!) I did try the <!--PW-REGION-DEBUG--> tool from the primary template file (auto-append from site config), but unfortunately that seemed to render exactly what was expected: the one switch that was made indeed got switched.

I made one error in my description of this problem, however: A die() statement inside the IF statement of the policy.php file does not render the content. The content is rendered if a die() statement is made within the callout.php field template, however.

Link to comment
Share on other sites

  • BrendonKoz changed the title to [SOLVED] Field template output removed from final template output?

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...