How to use field values inside FLEXIContent template instead of using field's HTML display

4 years 1 month ago - 4 years 1 month ago #56646 by iamrobert
Hi,

My field is showdesc:
1::Yes%% 0::No%%

In my template this works well:
<?php if (($this->item->fields['showdesc']->display) == "Yes"):?>
 
<h1>YES</h1>
<?php else:?>
<h1>No</h1>
<?php endif; ?>

However do I get the same result with the actual value '1' rather than "Yes"?
My client is thinking about going bilingual - so it won't work.

Thanks,

Robert

Please Log in or Create an account to join the conversation.

4 years 1 month ago - 4 years 1 month ago #56648 by ggppdk
Hello

you can access the value like this
$field_id = 19;
 
// Use in ITEM view / Category (multi-items) view
$fvals = $item->fieldvalues[$field_id];  // or $items[$i] for category view

See more here:
Using the raw value of a field inside a template file or inside a new custom field type


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star review. Thanks!

Please Log in or Create an account to join the conversation.

4 years 1 month ago - 4 years 1 month ago #56655 by iamrobert
Thanks - that solved my issue.

Here is my final code:
 <?php
// Set Field ID
$field_id = 30;
 
// Use in ITEM view
$fvals = $item->fieldvalues[$field_id]; 
 
if (!empty($fvals)) foreach ($fvals as $v) {
	if ( @unserialize($v)!== false || $v=== 'b:0;' ) $v = unserialize($v);
}
 
?>

Execute if Yes
<?php if ($v == "1"):?>
<h1>YES</h1>
<?php else:?>
<h1>No</h1>
<?php endif; ?>

Please Log in or Create an account to join the conversation.

2 weeks 3 days ago #77247 by iamrobert
If we are using a checkbox - this seems to work.

For mod_flexicontent we should use: $item->_row->fieldvalues

<?php 
/*
 *	=======================================================================
	+ SET TYPE OF NEWS CATEGORY
 *	=======================================================================
 */
// Set Field ID
$field_id = 234;
 
// SET NEWS TYPE
$news_type = array();
 
// Use in ITEM view
if(!empty($item->_row->fieldvalues[234])) {
$fvals = $item->_row->fieldvalues[$field_id]; 
} 
//VALUE
if (!empty($fvals)) foreach ($fvals as $v) {
	if ( @unserialize($v)!== false || $v=== 'b:0;' ) $v = unserialize($v);
  $news_type[] = $v;
 
}
 
 
?>

To call it later in your template:
<?php echo implode(' ', $news_type);?>

Please Log in or Create an account to join the conversation.

Moderators: vistamediajoomlacornerggppdk
© 2018 Flexicontent. All Rights Reserved.