Keyword

Hide some extra fields from public

  • Pablo Benitez
  • Pablo Benitez's Avatar Topic Author
  • Offline
  • New Member
More
10 years 2 months ago #130026 by Pablo Benitez
Hide some extra fields from public was created by Pablo Benitez
I want to hide the content of some of my extra fields from public and just let the admins to see them. How I can accomplish that?
CSS is not a good solution since the data will be hidden but present in the source html.
Thanks!

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 2 months ago #130027 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Hide some extra fields from public
<?php if(!JFactory::getUser()->guest): ?>
// RENDER YOUR EXTRA FIELD HERE
<?php endif; ?>

This will do the trick.

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

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

More
10 years 2 months ago #130028 by Maurilio
Replied by Maurilio on topic Re: Hide some extra fields from public
Hello, I have the same problem: show some fields ONLY to admins group.
But I'm not an expert in php, please can you tell me which php file I need to change and give me an example of code?
many thanks!

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 2 months ago #130029 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Hide some extra fields from public

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

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

More
10 years 2 months ago #130030 by Maurilio
Replied by Maurilio on topic Re: Hide some extra fields from public
Great! Thank you very much!
I don't know wery well PHP but I changed item.php and it seems to work.
This is the code:
<div class="itemExtraFields">
	  	<h3><?php echo JText::_('K2_ADDITIONAL_INFO'); ?></h3>
	  	<ul>
      <!-- GET USER -->
			<?php $user =& JFactory::getUser(); ?>
			<?php foreach ($this->item->extra_fields as $key=>$extraField): ?>
			<?php if($extraField->value != ''): ?>
			<li class="<?php echo ($key%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>">
				<?php if($extraField->type == 'header'): ?>
				<h4 class="itemExtraFieldsHeader"><?php echo $extraField->name; ?></h4>
				<?php else: ?>
				<span class="itemExtraFieldsLabel"><?php echo $extraField->name; ?>:</span>
        <!-- CHECK IF THIS IS THE FIELD TO HIDE FROM ALL EXCEPT ADMINISTRATOR -->
				<?php if($extraField->name == 'FIELDTOHIDE' && $user->id != ADMIN-ID): ?>
          <span class="itemExtraFieldsValue"><?php echo "*** FIELD HIDDEN ***"; ?></span>
        <?php else: ?>
				  <span class="itemExtraFieldsValue"><?php echo $extraField->value; ?></span>
				<?php endif; ?>
			</li>
			<?php endif; ?>
			<?php endforeach; ?>
			</ul>
	    <div class="clr"></div>
	  </div>

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

More
10 years 2 months ago #130031 by Maurilio
Replied by Maurilio on topic Re: Hide some extra fields from public
Now I have two final questions:
put item.php in templates/mytemplate/html/com_k2 / it's safe?
I mean: in no event override will not work by showing my hidden field OR
it's more safe change item.php in /components/com_k2/templates/ ?

I need change also generic.php or others php fiels?

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 2 months ago #130032 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Hide some extra fields from public
Everything you put in your template's folder will NOT be lost when you update.
So you must override them instead of just edit them.

All other files can overridden on a needed-only basis. eg: Are you displaying any extrafields in these view? If yes, then override them

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