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

More
2 years 10 months ago - 2 years 10 months 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
Last edit: 2 years 10 months ago by ggppdk.

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

More
2 years 10 months ago - 2 years 10 months 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!
Last edit: 2 years 10 months ago by ggppdk.

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

More
2 years 10 months ago - 2 years 10 months 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; ?>
Last edit: 2 years 10 months ago by iamrobert.

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

Moderators: vistamediajoomlacornerggppdk
© 2018 Flexicontent. All Rights Reserved.