Keyword

How to add k2 extra field inside the content

More
6 years 3 months ago #170879 by Alex
Hi to everyone. I have a question about K2 extra field: it's possible to call inside the content one or more k2 extra fields tag?

If so which tag or call i will need to use? Thanks

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

More
6 years 3 months ago - 6 years 3 months ago #170887 by JoomlaWorks
Replied by JoomlaWorks on topic How to add k2 extra field inside the content
Yes.

To directly output individual extra fields in your K2 overrides, do something like this (e.g. in item.php) to get the extra field name:
echo $this->item->extraFields->EXTRAFIELD_ALIAS_HERE->name;

To get the extra field value you would simply do this:
echo $this->item->extraFields->EXTRAFIELD_ALIAS_HERE->value;
echo $this->item->extraFields->EXTRAFIELD_ALIAS_HERE->rawValue; // for date type only

Simply replace EXTRAFIELD_ALIAS_HERE with the actual alias of the extra field you wish to output.

In modules, use:
echo $item->extraFields->EXTRAFIELD_ALIAS_HERE->value;
echo $item->extraFields->EXTRAFIELD_ALIAS_HERE->rawValue; // for date type only

Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Last edit: 6 years 3 months ago by JoomlaWorks.

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

More
6 years 3 months ago #170893 by Alex
Hi Fotis and thanks for your reply. Basically i need to call some of K2 extra field like shortcode to render data inside the article. Example:

Your name: (extra field > Name)

The result will be Your name: Fotis.

How i can do that? Thanks

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

More
6 years 3 months ago #170894 by JoomlaWorks
Replied by JoomlaWorks on topic How to add k2 extra field inside the content
When you say "need to call some of K2 extra field like shortcode to render data inside the article", do you actually mean the WYSIWYG editor? If so, this is not currently possible as it would require a plugin to do that (perhaps a generic plugin to render PHP would work).

However, is there really a point in doing that? The K2 item form is input and the resulting page in the frontend is output. You want to render the output into the input page. It would only confuse your users...

If you explain WHY you want to do this, I might be able to provide a more elegant solution.

Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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

More
6 years 3 months ago #170896 by Alex
Yes WYSIWYG editor. I use JCE that though the configuration option is possible to enable the function to add Php code inside the article.

The purpose about why i am thinking about the above, it's because it could save time to populate some data inside the article avoiding that the user can copy and paste manually all the time. Thanks

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

More
6 years 3 months ago #170898 by JoomlaWorks
Replied by JoomlaWorks on topic How to add k2 extra field inside the content
Then you should be looking at a plugin that copies the extra fields (values) from another item as its own. The gist is that both items should belong to categories that use the same extra fields group so that when you load to edit the item with the copied values, they show up just fine in the K2 item edit form.

Since this is a bit of an edge case, we can custom build the plugin for you if you sponsor it and we can open source it afterwards so it's constantly maintained by either us or other volunteers/users.

If you're interested, send us an email using the contact form here: www.joomlaworks.net/support/contact

Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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

  • Mohamed Abdelaziz
  • Mohamed Abdelaziz's Avatar
  • Offline
  • Platinum Member
  • Joomla Developer
More
6 years 3 months ago #170899 by Mohamed Abdelaziz
Replied by Mohamed Abdelaziz on topic How to add k2 extra field inside the content
Hi Alex,

I have developed the TExtrafield plugin 3 years ago

I think it will help you to add the extra fields inside the content, just with the shortcode {extrafield aliasname}

Where aliasname is the extrafield alias.

Multiple Extra Fields Groups for K2
AutoMeta for K2
Chained Fields for K2
More K2 Extensions In My Extensions Store

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

More
6 years 3 months ago #170900 by JoomlaWorks
Replied by JoomlaWorks on topic How to add k2 extra field inside the content
K2 Community to the rescue! Thank you Mohamed!

Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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

  • Mohamed Abdelaziz
  • Mohamed Abdelaziz's Avatar
  • Offline
  • Platinum Member
  • Joomla Developer
More
6 years 3 months ago #170901 by Mohamed Abdelaziz
Replied by Mohamed Abdelaziz on topic How to add k2 extra field inside the content
Thank you Fotis!
I'm always happy to help K2 community as much as I can.

Multiple Extra Fields Groups for K2
AutoMeta for K2
Chained Fields for K2
More K2 Extensions In My Extensions Store

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

More
6 years 3 months ago #170914 by Alex
Hi Mohamed thanks you very much for your help. I tried just now the plugin and works great. God bless you

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

More
6 years 2 months ago #171192 by Alex
Hi Mohamed how are you bro? It's possible also to add inside the Article "rate us" field? many thanks

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

  • Mohamed Abdelaziz
  • Mohamed Abdelaziz's Avatar
  • Offline
  • Platinum Member
  • Joomla Developer
More
6 years 2 months ago #171326 by Mohamed Abdelaziz
Replied by Mohamed Abdelaziz on topic How to add k2 extra field inside the content
Hi Alex,

I'm good, thanks!
If it is a k2 extra field, most probably yes.

Multiple Extra Fields Groups for K2
AutoMeta for K2
Chained Fields for K2
More K2 Extensions In My Extensions Store

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

More
4 years 6 months ago #177275 by Okan
Hello Fotis,

This one doesn't work with k2 tools module.
K2 plugins enabled.
It gives nothing.
And yes i used my own allias instead of "EXTRAFIELD_ALIAS_HERE"

<?php echo $item->extraFields->EXTRAFIELD_ALIAS_HERE->value; ?>

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

More
4 years 6 months ago #177295 by JoomlaWorks
Replied by JoomlaWorks on topic How to add k2 extra field inside the content
@Okan It's out of context ($item refers to something that is not globally defined), that's why.

I would recommend doing a K2 template override for item.php. A much better solution if you ask me...

Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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

More
3 years 11 months ago - 3 years 11 months ago #178902 by Stephan Tensen
Replied by Stephan Tensen on topic How to add k2 extra field inside the content
PROBLEM SOLVED, I MADE A VERY STUPID MISTAKE ;-) (assuming a field is filled without checking)

I'm a newbie, but very excited about the good things K2 can do ;-)
At the moment I'm trying to display one or more extra fields in the content. I tried using the first method in my override version of category_item.php. I tried it in two ways. See below. It's about the extra field with the alias Prijs. I added TEST1 above the code and TEST2 below the code, to make sure I'm editing the right file. I see TEST1 and TEST2 but the code in between seems to do nothing.

I also downloaded and installed the plugin TExtrafield from Mohammed, but no result either when putting {extrafield Prijs} in the editor of the introtext of the item. So clearly I must be doing something completely wrong ;-) I set display Extra Fields off, because I don't want it to show ALL extra fields. Is that correct? What can I be doing wrong?

TEST1
<?php if($this->item->extraFields->Prijs->value != ''): ?>
<div class="itemExtraFieldswrapper">
<div class="itemExtraFieldsLabel"> <?php echo $this->item->extraFields->Prijs->name; ?></div>
<div class="itemExtraFieldsValue"><?php echo $this->item->extraFields->Prijs->value; ?></div>
</div>
<?php endif; ?>

<?php echo $this->item->extraFields->Prijs->value; ?>
TEST2
Last edit: 3 years 11 months ago by Stephan Tensen. Reason: Problem solved

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


Powered by Kunena Forum