Keyword

Extra Fields Display based on user

  • CuppaJoe
  • CuppaJoe's Avatar Topic Author
  • Offline
  • New Member
  • Share The Warmth
More
10 years 7 months ago #125639 by CuppaJoe
Extra Fields Display based on user was created by CuppaJoe
Hi clever people.

I was reading this article: getk2.org/community/New-to-K2-Ask-here-first/169777-Hiding-certain-extra-fields regarding hiding specific extra fields, based on their alias.

I modified my item.php code to look like this:
<li class="<?php echo ucfirst($extraField->alias); ?> group<?php echo $extraField->group; ?>">
   <span class="itemExtraFieldsLabel"><?php echo $extraField->name; ?>:</span>
   <span class="itemExtraFieldsValue"><?php echo $extraField->value; ?></span>
</li>

So now each extrafield displayed in the list has a class name the same as its alias, which then allows a display:none to be added to the css, almost perfect, it works, but it is a bit dirty, if you inspect the page code the hidden class can still be seen.

Now my particular item.php, can only be seen by "registered" users and above, so I was thinking how can we check the logged in user and if they are user group "5" or "super admin" then display the extra field, else hide it.

Is it possible to add such control, if so, how?

Thanks in advance.

Regards,

Joe,

ShareTheWarmth

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

More
10 years 7 months ago #125640 by Lefteris
Replied by Lefteris on topic Re: Extra Fields Display based on user
Hi. Yes this is possible with some code in your template override. But it depends on the Joomla! version you are using. Example for Joomla! 2.5/3.2:
<?php
$user = JFactory::getUser();
if($user->authorise('core.admin')): ?>
// Your extra field here.
<?php endif; ?>

The above example will allow only users with the " Super Admin " permission to view the fields.

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

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

  • CuppaJoe
  • CuppaJoe's Avatar Topic Author
  • Offline
  • New Member
  • Share The Warmth
More
10 years 6 months ago - 10 years 6 months ago #125641 by CuppaJoe
Replied by CuppaJoe on topic Re: Extra Fields Display based on user
Hey Lefteris,

Thanks for your reply.

OK, just to confirm, I place that code at the top of the page, such as the index.php.

Unsure what to put in replace for the // Your extra field here.
Would that be something like:
<?php echo $this->item->extraFields->ALIASNAME->value; ?>

Thanks.

Regards,

Joe,

ShareTheWarmth

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

More
10 years 6 months ago #125642 by Lefteris
Replied by Lefteris on topic Re: Extra Fields Display based on user
Yes. Note that this condition checks against users that have the permission of "Super Admin".

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