Keyword

Registered users access to extrafields

  • DigiSol
  • DigiSol's Avatar Topic Author
  • Offline
  • New Member
More
9 months 2 days ago #171474 by DigiSol
DigiSol created the topic: Registered users access to extrafields
Hello everyone.

I have a website that works like products catalogue. In the products items, I have photo, description and some extra fields with specifications. I also want to add an extra field with price, but I want to be visible only to the registered users.

How is this possible with K2 2.9.0?

Thanks a lot.

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

  • Fotis
  • Fotis's Avatar
  • Away
  • Administrator
  • JoomlaWorks Support Team
More
9 months 2 days ago #171478 by Fotis
Fotis replied the topic: Registered users access to extrafields
First off, a primer on calling single extra fields...

=== 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

Now that you know how to call a specific extra field, you can simply wrap that field with some PHP code that checks if a user is logged in, e.g. (for the item view):
// Get user instance (if any)
$user = JFactory::getUser();

// Check if user is NOT a guest, then show the extra field
if (!$user->guest) {
    echo $this->item->extraFields->EXTRAFIELD_ALIAS_HERE->name;
}

If you use & love K2, please take a moment to add your review and rate it
at the Joomla Extensions Directory: extensions.joomla.org/extension/k2/


IMPORTANT: Please search the forum before posting a question!

JoomlaWorks Support Team Member

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


Powered by Kunena Forum