Jump to content

{Solved} FieldsetPage – show html structure only if a field is populated


neophron
 Share

Recommended Posts

Hi guys,

in a website with a lot of fieldsetpages I want to show in this case accordions, only if a field (body) is populated.

This is my faulty code:

<?php if ($page->sectionfield_fa_membership->body) : ?>
    <section class="membership">
        <ul uk-accordion>
          <li itemscope itemprop="mainEntity" itemtype="https://schema.org/Question">
            <a class="uk-accordion-title" href>
              <p itemprop="name">Membership</p>
            </a>
            <div class="uk-accordion-content" itemscope itemprop="acceptedAnswer" itemtype="https://schema.org/Answer">
              <div itemprop="text"><?= $page->sectionfield_fa_membership->body; ?></div>
            </div>
          </li>
        </ul>
    </section>
<?php endif ?>

I'm getting this error: Attempt to read property "body" on null

The logic is based on this code:

<?php
if ($page->body) {
  echo $page->body;
}
?>

 

Link to comment
Share on other sites

Are you triple sure sectionfield_fa_membership doesn't have any typo? (Doesn't look like it!)

Are you accessing $page in the right context? Seems you want to do this in a regular template file? You might be within a field rendered through wireRenderFile?

Link to comment
Share on other sites

  • neophron changed the title to {Solved} FieldsetPage – show html structure only if a field is populated

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

×
×
  • Create New...