332 Posts
Kenneth
9 years ago
3
Topic

Hi,

I've added a group x to my content type, and sometimes this group x fields is empty.

In my custom template, where I use SimpleSimon, I've tried doing this:

    <?php if (!empty($cck->get( 'content_groupx_field' )->value)): ?>
    <p> </p>
    <div class="artikkel_info">
      <h4>HEADING TO SHOW ONLY IF IT'S NOT EMPTY</h4>
      <?php foreach($cck->get( 'content_groupx_field' )->value as $gx){ ?>
      <a target="_blank" href="/<?php echo $gx['groupx_field1']->value; ?><?php echo $gx['groupx_field2']->value; ?>"><?php echo $gx['groupx_field3']->value; ?></a><br />
      <?php } ?>
    </div>
    <?php endif; ?>


But the if (!empty(.... dosn't seem to do anything.

I've done about 10.000 searches in the forum and the same amount in Google. I'm now hoping one fellow Sebloder might enlighten me. :)

Get a VIP membership
9 years ago
1
Level 1

Hello Kenneth,

when you don't know how to manage a field, you can try to display all of it's properties with the code 

$myfield = $cck->get('your_field');
echo "<pre>";
print_r( $myfield );
echo "<pre>";<br>

So with that you will be able see which property you need, and what kind of property it is (string, array, ...), to adapt your code.


best regards.

Lionel

332 Posts
Kenneth
9 years ago
0
Level 2

Hi,

Sorry for the late follow up. Been quite busy.

I've tried, and I can see that it starts with stdClass object, and then there's an array with a new stdClass object. And in there I can see the value that I can check. But I don't know how to adapt this code to go further than what you gave. 

332 Posts
Kenneth
9 years ago
0
Level 1

I managed to solve this. Not sure if this is the cleanest way to do it, but it works:

This is useful if you have a group x and create a custom template and then want to show something ONLY if there are any instances of group x filled.

I had a title that I only wanted to show if there was values in the group x fields, and then of course: not to have it show when nothing was set.

	
<?php 

$test_kilde = $cck->get('artikler_groupx_ekstern_info')->value;
$test_kilde2 = $test_kilde[0]['artikler_ekstern_info_beskrivelse']->value;
	


if(!empty($test_kilde2)) {
	echo "Something to show";
}
	
?>


Get a Book for SEBLOD