Keyword

Hide Extra Fields in the front end

  • Deborah
  • Deborah's Avatar Topic Author
  • Offline
  • New Member
More
8 years 2 months ago - 8 years 2 months ago #152098 by Deborah
Hide Extra Fields in the front end was created by Deborah
Hello.
Is there a way to hide some of my Extra Fields in the front end, or set access levels for each field?
I want to store many extra fields in the admin back end, but only have some of them published in the front end.
Is custom css the only way to go?
Thank you!
Last edit: 8 years 2 months ago by Deborah. Reason: additional info

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 #152108 by Krikor Boghossian
Replied by Krikor Boghossian on topic Hide Extra Fields in the front end
Yes,

You need to override K2's templates
getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates

Then you should render these fields one by one
github.com/kricore/Advanced-templating-with-K2/blob/master/_inc/cheatsheet.php#L104-L109

And using Joomla!'s user object - docs.joomla.org/Accessing_the_current_user_object
show/ hide the extrafield.

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

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

  • Deborah
  • Deborah's Avatar Topic Author
  • Offline
  • New Member
More
8 years 2 months ago - 8 years 2 months ago #152111 by Deborah
Replied by Deborah on topic Hide Extra Fields in the front end
Thank you Krikor.
My ability to code is extremely limited however!
I have created a sub-template, as you advised.
I am assuming that the extra field code from the cheatsheet would be added to item.php in that sub-template?

So, how would I make the Extra Field 'old-atlas' hidden from all front end users?
if( isset( $this->item->extraFields->item-name->value ) && ( $this->item->extraFields->item-name->value !== '') ) 
{
	$this->item->extraFields->item-name->name;
	$this->item->extraFields->item-name->value;
}

Thanks for your help.
Last edit: 8 years 2 months ago by Deborah. Reason: typos

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 #152122 by Krikor Boghossian
Replied by Krikor Boghossian on topic Hide Extra Fields in the front end
Yes, you assumed correctly :)
You need to read the "Determining Status" section of this post.
docs.joomla.org/Accessing_the_current_user_object

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

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

  • Deborah
  • Deborah's Avatar Topic Author
  • Offline
  • New Member
More
8 years 2 months ago - 8 years 1 month ago #152188 by Deborah
Replied by Deborah on topic Hide Extra Fields in the front end
Hi Krikor.
Thank you for your patience.
I have read the Accessing the current user object
I don't have a very well developed understanding of, or ability to write, php so I was hoping for a little more help please.

If I have an extra field "item_name" that I only want to be visible to "Publishers", for example, how would the github cheatsheet code, the user object code and the extra field code in item.php all go together to achieve this?

UPDATE:
As the User Object seems only to function in determining whether the user is a guest or not, I assume that I will have to make all items visible by using the cheatsheet method for all viewers.
So I am looking at something like the following:
<?php if($this->item->params->get('itemExtraFields') && count($this->item->extra_fields)): ?>
	  <!-- Item extra fields -->
	  <?php $user = JFactory::getUser();
 	if ($user->guest): ?>
<?php 
	if( isset( $this->item->extraFields->EXTRAFIELDALIASHERE->value ) && ( $this->item->extraFields->EXTRAFIELDALIASHERE->value !== '') ) 
	{
		$this->item->extraFields->EXTRAFIELDALIASHERE->name;
		$this->item->extraFields->EXTRAFIELDALIASHERE->value;
	}
?>
<?php else>
<?php 
	if( isset( $this->item->extraFields->EXTRAFIELDALIASHERE->value ) && ( $this->item->extraFields->EXTRAFIELDALIASHERE->value !== '') ) 
	{
		$this->item->extraFields->EXTRAFIELDALIASHERE->name;
		$this->item->extraFields->EXTRAFIELDALIASHERE->value;
	}
?>

Can you help me organise that code so that it works please?

Many thanks
Last edit: 8 years 1 month ago by Deborah. Reason: update

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 1 month ago #152306 by Krikor Boghossian
Replied by Krikor Boghossian on topic Hide Extra Fields in the front end
You are halfway there Deby.
The else: ?> typo I think it has already been corrected.

The user's groups can be retrieved like this:
$user_groups = $user->groups;
You can see the ids in the user groups' view.

Then using PHP's in_array() - php.net/manual/en/function.in-array.php - you can check if that user belongs to a certain usergroup.
	if (in_array( GROUP_ID, $user_groups)) {
		echo 'extrafield code here';
	}

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

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

  • Deborah
  • Deborah's Avatar Topic Author
  • Offline
  • New Member
More
8 years 1 month ago - 8 years 1 month ago #152334 by Deborah
Replied by Deborah on topic Hide Extra Fields in the front end
Thanks again.
I really know very little about php stuff, all the ":? > : ))" makes my eyes roll!
I have, however, managed to cobble something together after hunting around, and finding useful info in
this lively thread from around 2012

No doubt I'll have more questions...

Regards
Last edit: 8 years 1 month ago by Deborah. Reason: link

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 1 month ago #152369 by Krikor Boghossian
Replied by Krikor Boghossian on topic Hide Extra Fields in the front end
We 'll be here :)

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