- Posts: 9
COMMUNITY FORUM
Hide some extra fields from public
- Pablo Benitez
-
Topic Author
- Offline
- New Member
Less
More
10 years 10 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!
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
-
- Offline
- Platinum Member
Less
More
- Posts: 15920
10 years 10 months ago #130027
by Krikor Boghossian
This will do the trick.
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.
Please Log in or Create an account to join the conversation.
- Maurilio
-
- Offline
- New Member
Less
More
- Posts: 3
10 years 10 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!
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
-
- Offline
- Platinum Member
Less
More
- Posts: 15920
10 years 10 months ago #130029
by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Hide some extra fields from public
This thread has some interesting examples:
getk2.org/community/English-K2-Community/160258-Hiding-specific-extra-fields-from-public#196154
As for which files you need to edit, you have to read this post.
getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates
getk2.org/community/English-K2-Community/160258-Hiding-specific-extra-fields-from-public#196154
As for which files you need to edit, you have to read this post.
getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates
Please Log in or Create an account to join the conversation.
- Maurilio
-
- Offline
- New Member
Less
More
- Posts: 3
10 years 10 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:
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.
- Maurilio
-
- Offline
- New Member
Less
More
- Posts: 3
10 years 10 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?
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
-
- Offline
- Platinum Member
Less
More
- Posts: 15920
10 years 10 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
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
Please Log in or Create an account to join the conversation.