Jump to content

Inputfield Dependencies in your template


fnode
 Share

Recommended Posts

Hello,

I'm loving Inputfield Dependencies in PW 4.

I have the following fields:

Fields:

- columnOption : Page : Input type Select

..... No Section

..... Batch ?id=1016

..... Font Awesome ?id=1017

- batchClass : Text : showIf columnOption=1016 //Batch CSS Class 

- batchDataIcon : Text : showIf columnOption=1016 //Batch Icon Data

- faClass : Text : showIf columnOption=1017 //Font Awesome

Template:

- home : column

- column : All fields from above

For example:

     I select Font Awesome and faClass:field appears I input fa-code-fork. If I choose another option, content for faClass:field still remains in my template.

How can I check if a selected option is active or not with showIf in a template. I hope I'm making sense. I attached images for you to see.

Code basic : home.php

<?php foreach ($page->column as $c) : ?>

<div class="four columns icons">
    <i class="icon <?php echo $c->batchClass ?>" data-icon="<?php echo $c->batchDataIcon ?>"></i>
    <h3><?php echo $c->title ?></h3>
    <p><?php echo $c->body ?></p>
</div>

<?php endforeach ?>

Thank you!

post-118-0-28625800-1394214685_thumb.png

post-118-0-57721300-1394214697_thumb.png

post-118-0-45329400-1394214704_thumb.png

Link to comment
Share on other sites

  • 2 weeks later...

Your showIf statements look alright to me, though I don't think that matters to what you are trying to achieve here. Assuming I understand correctly, $page->column is a PageArray of pages under /columns/ and you want to access the $columnOption property of those pages, which are themselves page references. (Either: Batch and Font Awesome). Your code for home.php seems correct, except that you aren't accessing the $columnOption property at all in your code. You'd mentioned "checking if a selected option is active or not". Is something like this what you are trying to achieve?

foreach($page->column as $c) {
  if($c->columnOption->name == 'batch') {
    // output Batch icon
    echo "<i class='icon $c->batchClass' data-icon='$c->batchDataIcon'></i>";
  } else if($c->columnOption->name == 'fa') {
    // output Font Awesome icon
    echo "<i class='fa $c->faClass'></i>";
  }
  // output everything else
  echo "<h3>$c->title</h3><p>$c->body</p>";
}
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...