How to render an extrafield?

December 2012 Joomla Template
Rate this topic: Evaluations: 1, 1.00 on the average.Evaluations: 1, 1.00 on the average.Evaluations: 1, 1.00 on the average.Evaluations: 1, 1.00 on the average.Evaluations: 1, 1.00 on the average.Evaluations: 1, 1.00 on the average.1.00 out of 6 based on 1 vote(s)
GK User
Fri Sep 19, 2014 3:04 pm
Reply with quote
Report this post
I need to have an opportunity to leave links in description of images.
At K2 forum admin has advised me to make it what way:

"You must create an extra field of type "Link" or "Textarea" and then render this field in your template. Of course this requires to create a template override. You can read more regarding K2 template overrides at getk2.org/documentation/tutorials/174-te...pts-of-sub-templates ."


I need the code for overrides. Could somebody write how to make It the advised way or another?
User avatar
Fresh Boarder

teitbite
Sun Sep 21, 2014 11:16 am
Reply with quote
Report this post
Hi

You need to edit /html/com_k2/templates/default/item.php and than use the $this->item->extra_fields variable, but I really do not know what You want to do with it, so I cannot tell how this variable should be used.
User avatar
Moderator

GK User
Tue Sep 23, 2014 3:57 pm
Reply with quote
Report this post
Hello! Glad to meet you again.

I want to have an opportunity to add links to description of images. And want to do it with k2 frontend.

picture1.jpg


But have only text not linkable as a result.

picture2.jpg


At k2 forum I was advised to use an extrafield and to render it to place the link into description.
Do you have any ideas?
User avatar
Fresh Boarder

teitbite
Wed Sep 24, 2014 2:24 pm
Reply with quote
Report this post
Hi

This is a customisation request, so we do not support that, but You will need to edit file /html/com_k2/template/default/item.php look for code:

Code: Select all
                    <span class="itemImageCaption"><?php echo $this->item->image_caption; ?></span>


and replace it with:

Code: Select all
                    <?php foreach($this->item->extra_fields as $key=>$extraField): ?>
                       <?php if( $extraField->id == 'ID_OF_OXTRA_WIELD_WITH_ADDRESS' ) ?>
                           <?php $captionURL = $extraField->value; ?>
                       <?php endif; ?>
                    <?php endif; ?>

                    <span class="itemImageCaption"><a href="<?php echo $captionURL; ?>"><?php echo $this->item->image_caption; ?></a></span>



Somethig like this. The above may not be accurate.
User avatar
Moderator

GK User
Tue Sep 30, 2014 5:56 pm
Reply with quote
Report this post
Thank you for trying. It doesn't work( I know it is not your fault. Thanks for giving the way to find the resolving of the problem.
User avatar
Fresh Boarder

teitbite
Thu Oct 02, 2014 10:56 am
Reply with quote
Report this post
Hi

I've written this from a memory so this may have a typo or two, but this is a solution I've used couple of times, so I'm sure it will work. Please send me an access to ftp and the url to the article You have this field used, so I'll try.

PS: I think that extrafields needs to be enabled for this to work in category settings.
User avatar
Moderator


cron