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

More
8 years 7 months ago - 8 years 7 months ago #56646 by iamrobert
Hi,

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

In my template this works well:
Code:
<?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: 8 years 7 months ago by ggppdk.

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

More
8 years 7 months ago - 8 years 7 months ago #56648 by ggppdk
Hello

you can access the value like this
Code:
$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...
Last edit: 8 years 7 months ago by ggppdk.
The following user(s) said Thank You: iamrobert

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

More
8 years 7 months ago - 8 years 7 months ago #56655 by iamrobert
Thanks - that solved my issue.

Here is my final code:
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
Code:
<?php if ($v == "1"):?> <h1>YES</h1> <?php else:?> <h1>No</h1> <?php endif; ?>
Last edit: 8 years 7 months ago by iamrobert.

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

More
4 years 5 months ago #77247 by iamrobert
If we are using a checkbox - this seems to work.

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

Code:
<?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:
Code:
<?php echo implode(' ', $news_type);?>

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

More
4 years 1 month ago #78048 by iamrobert
FLEXIcontent now has the option of showing the value in the frontend vs the label:

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

Moderators: vistamediajoomlacornerggppdk
Time to create page: 0.298 seconds
Save
Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Essential
These cookies are needed to make the website work correctly. You can not disable them.
Display
Accept
Analytics
Tools used to analyze the data to measure the effectiveness of a website and to understand how it works.
Google Analytics
Accept
Decline