Keyword

Registered users access to extrafields

  • DigiSol
  • DigiSol's Avatar Topic Author
  • Offline
  • New Member
More
5 years 8 months ago #171474 by DigiSol
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.

More
5 years 8 months ago #171478 by JoomlaWorks
Replied by JoomlaWorks on 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;
}

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