Calling fieldx and groupx

How to call fieldx and groupx in your custom template.

Fieldx and groupx store are a little different than most other fields, because they contain multiple values. In Seblod 2.0, there are two main options for displaying them in a custom template

Honoring all parameters and typos set in the backend


$cck->renderField( 'your_fieldx_or_groupx' );
Because it outputs the loop plus formatting, renderfield is quick and easy and works well in some cases.

Fieldx Raw with no formatting

<?php foreach($cck->get( 'your_fieldx' )->value as $fx){ ?>
  <img src="<?php echo $fx->value; ?>" alt="<?php echo $fx->image_alt; ?>" title ="<?php echo $fx->image_title; ?>" />
<?php } ?>

Groupx Raw with no formatting

<?php foreach($cck->get( 'your_groupx' )->value as $gx){ ?>
  <p><img src="<?php echo $gx['your_image']->value; ?>" alt="<?php echo $gx['your_image']->image_alt; ?>" title ="<?php echo $gx['your_image']->image_title; ?>" /></p>
  <p><?php echo $gx['text_field']->value; ?></p>
  <p><?php echo $gx['second_text_field']->value; ?><p>
<?php } ?>
The advantage of getting the raw values is that you have complete control over the html that is created. Useful when you are working, particular layouts or scripts, or you just want the leanest possible code.

Bonus option

$cck->get( 'your_field' )->html;

I haven't tested this much yet, but it seems to leave out typos but renders some basic html. For example, an image filed would output:

<img src="/path/to/the/image" alt="your alt text" title="your title text" />

Compare that to $cck->get( 'your_field' )->value; which literally returns just the path. Note: This doesn't eliminate the need for a loop like $cck->renderField.

Ok now have some fun!

unleash.it
December 02, 2011
2146

About Author

avatar

unleash

unleash.it

United States