Keyword

Display Extra Fields only to Certain Users or Access Levels

  • Michael Yaeger
  • Michael Yaeger's Avatar Topic Author
  • Offline
  • Premium Member
More
8 years 2 months ago #151323 by Michael Yaeger
I have a series of extra fields for my K2 items that I only want to show to logged in users. To add more, I need to show one field to one User Group and a different field to a different User Group. How, can I accomplish this?

I know I can do access level checks for modules, but since these are extra fields attached to K2 items, I'm fumbling for a way to accomplish this.

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

  • Michael Yaeger
  • Michael Yaeger's Avatar Topic Author
  • Offline
  • Premium Member
More
8 years 2 months ago #151371 by Michael Yaeger
Someone suggested: "You need to override the display for your custom fields view." As opposed to overriding the output of the extra fields, is there a plugin that adds "Access Level" to each extra field? If I could do something like that, it would work nice!

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 2 months ago #151375 by Krikor Boghossian
Replied by Krikor Boghossian on topic Display Extra Fields only to Certain Users or Access Levels
The out of the box solution would be the overrides.
If you are looking for a more robust solution, you have to look for such a plugin in the JED, or the KED getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates

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

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

  • Michael Yaeger
  • Michael Yaeger's Avatar Topic Author
  • Offline
  • Premium Member
More
8 years 2 months ago #151392 by Michael Yaeger
I was able to accomplish this using my existing template with the following code (in abbreviated form):
<?php $user = JFactory::getUser(); ?>
<?php if(!$user->guest): ?>
<!-- Prices -->
<div class="moduletable">
    <h3 class="specs">Pricing</h3>
    <?php
      $none = true; 
      foreach ($this->item->extra_fields as $key=>$extraField) {
        if($extraField->value && $extraField->name=='Price A' && in_array(25,$user->groups)) {
          echo $extraField->value;
          $none = false;
          break;
        }
        elseif($extraField->value && $extraField->name=='Price B' && in_array(26,$user->groups)) {
          echo $extraField->value;
          $none = false;
          break;
        }
      }
      if ($none) echo '<br/><p>Coming Soon!</p>';
    ?>
</div>
<?php endif; ?>
Basically, I check to see if the user is logged in, then run through the extra fields to see if the field name is "Price A" and the user is in the user group "Price A" (ID=25). If it matches, I output the price and move on. If not, it does the same check for "Price B." If an extra field for price isn't assigned or the user doesn't have a price level, I give a encouraging message! ;)

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 2 months ago #151394 by Krikor Boghossian
Replied by Krikor Boghossian on topic Display Extra Fields only to Certain Users or Access Levels
One small hint.

Use a system plugn which does not allow users to switch templates via the ?template=template_name url suffix.

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

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

  • Michael Yaeger
  • Michael Yaeger's Avatar Topic Author
  • Offline
  • Premium Member
More
8 years 2 months ago #151396 by Michael Yaeger
Interesting...I tried adding "?template=default" to the URL, but nothing changed:
- surfaceartinc.com/tile/collections/venetian-reale/itemlist/category/13-antique-onyx.html?template=default
- surfaceartinc.com/tile/collections/venetian-reale/itemlist/category/13-antique-onyx.html

They are both the same. However, I'm very interested in adding additional security if needed...

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 2 months ago #151403 by Krikor Boghossian
Replied by Krikor Boghossian on topic Display Extra Fields only to Certain Users or Access Levels
It seems that you are covered in this situation. I cannot render your site in the protostar (default) template.

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

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

  • Michael Yaeger
  • Michael Yaeger's Avatar Topic Author
  • Offline
  • Premium Member
More
8 years 2 months ago #151418 by Michael Yaeger
Yes, I strip out as much of the Joomla! "clutter" as I can, including any unnecessary templates, plugins, components, etc. I thought you were saying someone could force a different K2 layout template, which would not be good while trying to restrict extra fields.

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 2 months ago #151422 by Krikor Boghossian
Replied by Krikor Boghossian on topic Display Extra Fields only to Certain Users or Access Levels
By default you can switch templates in Joomla! sites by using the ?template=tempaltename

stackoverflow.com/questions/2851311/show-template-in-joomla-parameter

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