11 years ago
4
Topic

Hello everybody and thank you for reading,

one little question about hiding fields in a custom template.

My goal is to give my client the option to fill a special field, but if he does not wnat to or whatever, the field shout be hidden on the output.

My code looks like this...

<tr>
  <td><h5><?php echo $cck->getLabel( 'field_name1' ); ?></h5></td>
  <td><?php echo $cck->renderField( 'field_name1' ); ?></td>
</tr>

... and i would like to do something like this

(in my own word)

<?php  "if not empty" .... ?>
   <tr>
     <td><h5><?php echo $cck->getLabel( 'field_name1' ); ?></h5></td>
     <td><?php echo $cck->renderField( 'field_name1' ); ?></td>
   </tr>
<?php } ?>


Sorry, i guess it´s a stiupid question and my english is bad.
I would be glad if someone could help me
thanks in advance

Mirco



Get a VIP membership
2 Posts
fox
10 years ago
3
Level 1
Hello mirco
you can change x with what you want but you have to use a different one if you will duplicate the code

<?php

$x=$cck->getValue('field_name1');


if (empty($x)): ?><?php else: ?>


<tr>
<td><h5><?php echo $cck->getLabel( 'field_name1' ); ?></h5></td>
<td><?php echo $cck->renderField( 'field_name1' ); ?></td>
</tr>


<?php endif; ?>
10 years ago
2
Level 2

Thanks Fox very much,

It worx for me, with tiny changes, here are the code that works for me:

<?php $x=$cck->getValue('field_name'); if (empty($x)): ?><?php else: ?>

<h4> <?php echo $cck->getLabel('field_name');?> <a id="value" style="text-transform: none;"> <?php echo $cck->renderField('field_name');?> </a></h4> <?php endif; ?>

Thanx my Friend :)

2 Posts
fox
10 years ago
1
Level 3

Cool, welcome anytime my friend :)

64 Posts
Topy
7 years ago
0
Level 4

And if i have a html code inside echo ??

<?php $stea = $cck->getValue('stele'); if($stele !='') { echo ""; } else{ echo "<img src=\"/templates/protostar/images/system/$stea \">"; } ?>

How can i hide img tag if checkbox is not checked ?

Get a VIP membership