- Posts: 2
COMMUNITY FORUM
How to display extra fields in K2 component
- NAEEM ISHAQ
- Topic Author
- Offline
- New Member
Less
More
11 years 1 week ago - 11 years 1 week ago #120736
by NAEEM ISHAQ
How to display extra fields in K2 component was created by NAEEM ISHAQ
How to display extra fields in component with K2. Actually I want to add some field to displaying an introduction of that item image(e.g. Image to download template as title, image itself along with some introduction of that template), How to do please help me in this regard.
another words
"How to display k2 extra field just beside the image of k2 item"
Thanks :kiss:
another words
"How to display k2 extra field just beside the image of k2 item"
Thanks :kiss:
Please Log in or Create an account to join the conversation.
- Yiota
- Visitor
11 years 1 week ago #120737
by Yiota
Replied by Yiota on topic Re: How to display extra fields in K2 component
First of all you will have to create K2 template overrides. Read here on how overrides work getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates
Then you will have to modify the item.php file in order for this particular extra field to show next to the image.
After you have located the itemImage block of code you can target the specific extra field through these lines of code:
You will probably want to place them in a <div class="YOUR_CLASS"> container in order to style them afterwards and place them next to your image.
Then you will have to modify the item.php file in order for this particular extra field to show next to the image.
After you have located the itemImage block of code you can target the specific extra field through these lines of code:
<?php echo $this->item->extraFields->THE EXTRA FIELD ALIAS->label; ?>
<?php echo $this->item->extraFields->THE EXTRA FIELD ALIAS->value; ?>
You will probably want to place them in a <div class="YOUR_CLASS"> container in order to style them afterwards and place them next to your image.
Please Log in or Create an account to join the conversation.
- Odin Mayland
- Offline
- Platinum Member
Less
More
- Posts: 404
11 years 5 days ago #120738
by Odin Mayland
Replied by Odin Mayland on topic Re: How to display extra fields in K2 component
Is it possible to use similar code in the K2 item description to display an extrafield value?
<?php echo $this->item->extraFields->alias->value ;?>
When I try using nonumber.nl Sourcerer in order to put PHP code in the K2 Item I get this error:
Fatal error: Using $this when not in object context in /home/goodwin/public_html/xjoomla/plugins/system/sourcerer/helper.php(552) : runtime-created function on line 7
Nonumbers support states that it didn't work because, "That's because $this->item-> is not known. Sourcerer doesn't magically create that variable for you. "
Please help me display extrafields using JCE in a K2 item description.
<?php echo $this->item->extraFields->alias->value ;?>
When I try using nonumber.nl Sourcerer in order to put PHP code in the K2 Item I get this error:
Fatal error: Using $this when not in object context in /home/goodwin/public_html/xjoomla/plugins/system/sourcerer/helper.php(552) : runtime-created function on line 7
Nonumbers support states that it didn't work because, "That's because $this->item-> is not known. Sourcerer doesn't magically create that variable for you. "
Please help me display extrafields using JCE in a K2 item description.
Please Log in or Create an account to join the conversation.
- Yiota
- Visitor
11 years 4 days ago #120739
by Yiota
Replied by Yiota on topic Re: How to display extra fields in K2 component
You cannot call up a variable like that through the editor I'm afraid. You need to use it in the item.php located on your template overrides.
Please Log in or Create an account to join the conversation.
- Odin Mayland
- Offline
- Platinum Member
Less
More
- Posts: 404
11 years 4 days ago - 11 years 4 days ago #120740
by Odin Mayland
Replied by Odin Mayland on topic Re: How to display extra fields in K2 component
I have successfully been able to make those calls in the item.php on other projects. Here is a good example: www.modernmagic.com/blog/joomla-technical-support/k2-table-like-list-in-category-view.html
The whole reason for using K2 on this latest project is for the extrafields, so it would be great to use them in the K2 item description.
Is it possible to create the K2 object that contains that K2 item.
So your code would en up like:
$k2 = someK2Function();
echo $k2->item->extraFields->alias->value ;
Or:
$k2 = someK2ItemFunction();
echo $k2->extraFields->alias->value ;
Do you think it is possible with some custom k2 plugin, custom development, etc?
The whole reason for using K2 on this latest project is for the extrafields, so it would be great to use them in the K2 item description.
Is it possible to create the K2 object that contains that K2 item.
So your code would en up like:
$k2 = someK2Function();
echo $k2->item->extraFields->alias->value ;
Or:
$k2 = someK2ItemFunction();
echo $k2->extraFields->alias->value ;
Do you think it is possible with some custom k2 plugin, custom development, etc?
Please Log in or Create an account to join the conversation.
- Matt Thomas
- Offline
- New Member
Less
More
- Posts: 9
11 years 4 days ago #120741
by Matt Thomas
Replied by Matt Thomas on topic Re: How to display extra fields in K2 component
Hi Jeff,
I've never tried this, but what if you used a custom short code, like {extrafield name}, in the item description, and the do a replace of the shortcode with the extra field value in the sub-template?
I've never tried this, but what if you used a custom short code, like {extrafield name}, in the item description, and the do a replace of the shortcode with the extra field value in the sub-template?
Please Log in or Create an account to join the conversation.
- Odin Mayland
- Offline
- Platinum Member
Less
More
- Posts: 404
11 years 4 days ago #120742
by Odin Mayland
Replied by Odin Mayland on topic Re: How to display extra fields in K2 component
The {extrafield alias} is exactly what I was thinking.
Where can I learn to "do a replace of the shortcode with the extra field value in the sub-template"?
Where can I learn to "do a replace of the shortcode with the extra field value in the sub-template"?
Please Log in or Create an account to join the conversation.
- Matt Thomas
- Offline
- New Member
Less
More
- Posts: 9
11 years 4 days ago #120743
by Matt Thomas
Replied by Matt Thomas on topic Re: How to display extra fields in K2 component
PHP's str_replace function should do the trick (php.net/manual/en/function.str-replace.php)
So, something like:
$extrafieldvalue = $this->item->extraFields->THE EXTRA FIELD ALIAS->value;
$this->item->description = str_replace('{extrafield alias}', $extrafieldvalue, $this->item->description);
So, something like:
$extrafieldvalue = $this->item->extraFields->THE EXTRA FIELD ALIAS->value;
$this->item->description = str_replace('{extrafield alias}', $extrafieldvalue, $this->item->description);
Please Log in or Create an account to join the conversation.