Keyword

Link in custom modul from database

  • Henrik Brogaard
  • Henrik Brogaard's Avatar Topic Author
  • Offline
  • New Member
More
5 years 3 weeks ago #171637 by Henrik Brogaard
Link in custom modul from database was created by Henrik Brogaard
I would like to create a custom module where an external link to a webshop must be made from one of my extra fields in a given article

For example, if it is a review of a new Pearl Jam album.
In one of my extra fields, the band is named Pearl Jam
There I would like to create a module that says
"Buy this or other albums from Pearl Jam here"
As links to website.com/search?q=Pearl+jam

But how do I do that?
I know I have to finde the information from my extra fields in the database and put it in as a link
<a href='website.com/search?q={$row}'>

I hope someone can help me.

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

More
5 years 3 weeks ago - 5 years 3 weeks ago #171640 by JoomlaWorks
Replied by JoomlaWorks on topic Link in custom modul from database
If you add the info in each item's extra fields, you can simply call *specific* extra fields (and not the entire loop) by using the extra field alias value. More specifically:

=== Call specific extra fields in K2 templates ===
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

This way you can call any URL wherever you want inside your item.php template override.

* I have added this as a tip in K2's docs here: getk2.org/documentation/tips-a-tricks/2667-display-single-extra-fields-anywhere-in-your-k2-content

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

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

  • Henrik Brogaard
  • Henrik Brogaard's Avatar Topic Author
  • Offline
  • New Member
More
5 years 3 weeks ago #171658 by Henrik Brogaard
Replied by Henrik Brogaard on topic Link in custom modul from database
thank you very much
It works perfectly by overwriting the K2 template.

Unfortunately, it does not work in a custom module.
my code is:
{source}
<?php echo $item->extraFields->BandKunstner->value; ?>
<?php echo $item->extraFields->BandKunstner->rawValue; // for date type only ?>
{/source}

What am I doing wrong?

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

  • Henrik Brogaard
  • Henrik Brogaard's Avatar Topic Author
  • Offline
  • New Member
More
5 years 2 weeks ago #171678 by Henrik Brogaard
Replied by Henrik Brogaard on topic Link in custom modul from database
I dont follow.
What do you Mean?

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

More
5 years 1 week ago #171737 by JoomlaWorks
Replied by JoomlaWorks on topic Link in custom modul from database
@Henrik

The code does not work in a custom module because it's out of context. "$this->item" refers to the current K2 item being displayed by the K2 component. That's why you can utilize this code in the item.php override.

If you want to use this code in a side module on the item view or elsewhere, you'll need to get the item ID from the request/URL and then perform a custom query, parse the results to load extra fields and then render the field you want. Which is probably overkill... However there are ready-made modules that can load item elements, so your best bet is to find one and override it with the code I gave you.

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 9 months ago #176555 by Sebastian Kalak
Replied by Sebastian Kalak on topic Link in custom modul from database
I warmly welcome,

I have a problem with the extra fields. Currently, I have a multiple-choice list set in the back. And now I would like them to be displayed one below the other on the front side, and there is a comma between them.

Can you count on any help?

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

More
3 years 9 months ago #176559 by JoomlaWorks
Replied by JoomlaWorks on topic Link in custom modul from database
@Sebastian Please create a new thread :)

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

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


Powered by Kunena Forum