- Posts: 2
COMMUNITY FORUM
Display specific extra field in module position ?
- Iannis Camillieri
- Offline
- New Member
With that configuration, I should be able to use K2 extrafields aliases with :
$this->item->extraFields->EXTRAFIELDALIASHERE->name
and
$this->item->extraFields->EXTRAFIELDALIASHERE->value
as it is explained here
getk2.org/blog/item/1068-k2-v262-now-available
to display a specific extra field.
Is there a way to use that code in a K2 Tool module (with the personalized code option) so I could display my extra field in a specific location without creating a K2 module sub template?
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
- Offline
- Platinum Member
- Posts: 15920
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Iannis Camillieri
- Offline
- New Member
- Posts: 2
This works fine but I can't choose witch specific extra field to display. With K2 BNR Content module, It's all or none.
I saw that since K2 v2.6.2 there's a way to call a specific extra field using its alias in PHP code ($this->item->extraFields->EXTRAFIELDALIASHERE->name ). But this code seems to be used in a sub template. As I don't know much of PHP language and how to create and use sub templates, I would like to know if there an easier way to use that code in a module.
Thanks for your help.
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
- Offline
- Platinum Member
- Posts: 15920
The code is pretty straight forward (it is a c/p snippet) and you shouldn't have any issues creating a new subtemplate.
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Joe Campbell
- Offline
- Platinum Member
- Posts: 438
When I attempt to use the standard code, it renders a blank screen:
<?php echo $this->item->extraFields->ExtraFieldAlias->value; ?>
I also tried using the BNR module - which only shows all extra fields (as mentioned by Iannis Camillieri in a previous post). When I tried using the module, it rendered a blank screen.
What is the "specific" code needed to utilize a K2 Content module to displaying an Extra Field?
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
- Offline
- Platinum Member
- Posts: 15920
In the K2 Content module you do not need $this.
<?php echo $item->extraFields->ExtraFieldAlias->value; ?>
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- baggiesmad
- Offline
- New Member
- Posts: 15
Krikor Boghossian wrote: This code is not intended for the BNR module.
In the K2 Content module you do not need $this.
<?php echo $item->extraFields->ExtraFieldAlias->value; ?>
Tried the following in my default.php template file but doesnt display anything...
<?php
if (!isset($item->extraFields))
{
$item->extraFields = new stdClass;
}
foreach ($item->extra_fields as $extraField)
{
$tmpAlias = $extraField->alias;
$item->extraFields->$tmpAlias = $extraField;
}
?>
<div class="moduleItemExtraFields"><span class="moduleItemExtraFieldsValue"><?php echo $item->extraFields->JobID->value; ?></span>
Please Log in or Create an account to join the conversation.