Hide menu item when logged in

14 years 3 weeks ago #127510 by chuckbone
Replied by chuckbone on topic Re:Hide menu item when logged in
Dude they've already told you what you need to know. Hiding stuff from logged in users is easy. Just..

[code:1]
$user = JFactory::getUser(); // get user object
[/code:1]

then, just enclose what you want to show to guests only in an if statement:

[code:1]
if($user->guest) {
//show tab or menu or module or whatever
}
[/code:1]

put that in your template index file, or if you are using it in a component in the template file for that component. It's pretty simple. The joomla CMS sets the guest property of the user object to 1 when you are not logged in, and 0 if you are a logged in user.

Post edited by: chuckbone, at: 2010/03/21 17:45

Post edited by: chuckbone, at: 2010/03/21 17:46

Please Log in to join the conversation.

14 years 3 weeks ago #127518 by guidoterhorst
Replied by guidoterhorst on topic Why shout?
I am one of people posting in this thread, and I am really surprised about the way this thread is developing.

It is fully unacceptable to being accused of hijacking in public, and I agree with the defense of the person who revived this topic. If you think somebody is hijacking, just delete the post and inform the poster why. Don't try to disgrace him publicly.

Second, It is clear from all that the poster writes in order to clarify his request, he is not only talking about menu items, but of a more general concept of hiding. However, being able to read that in his post requires some empathy and recognition of his experience level with joomla or php in general.

Thirdly, why give an example to the readers which clearly is not going to work without the reader having the capacity to fill in the "obvious" parts? The person who revived the post clearly has no programming capacities, otherwise he would have been capable of "doing the trick" himself.

Therefore, I dare both people who took the energy to reply to the request of this person in an unpleasant and provoking way, to post a solution on how to hide certain things based on user level, to hint him to a proper post explaining him howto, or, if you stand up to your attitude "it is obvious", explain it yourself "in a working example".

Thanx for not removing this remark to this topic.

Salam Aleikum (May peace be with you)

Please Log in to join the conversation.

14 years 3 weeks ago #127596 by jakobe75
Replied by jakobe75 on topic Re:Hide menu item when logged in
are you replying here to answer my questions from another thread?

the previous suggestion mentioned nothing of adding code to the index file.

your method confuses me,
can this not be achieved inside of CSsubs?


please clarify.

Post edited by: jakobe75, at: 2010/03/22 14:54

Please Log in to join the conversation.

14 years 3 weeks ago #127603 by krileon
Replied by krileon on topic Re:Hide menu item when logged in
Please let me clarify.
  1. You can NOT -hide- a menu item using CBSubs.
  2. You CAN -protect- a menu item using CBSubs.

In order to HIDE a menu item you need an ADDITIONAL module position within your JOOMLA -template-. You then need this module position to ONLY show to public users (see chuckbone's post as to how to do that).

It's also not possible to show a Tab to someone not logged in then remove it when someone is logged in, you CAN achieve something similar by using a Delimiter field to show/hide the content you intended to include in the tab; then set nothing else to show on the tab and configure CB to not show empty tabs (CB Configuration -> User Profile), your tab will vanish to logged in users.

To use the delimiter field method you'd need to use advanced substitutions such as IF statements (covered in tutorials within my signature) such as the following example.

[code:1]
[cb:if user="#displayedOrMe" user_id="0"]Content I would like only Guests to see.[/cb:if]
[/code:1]

Things do not work in such a fashion, because Joomla or CB do not work in a reverse permissions architecture. They're designed to give additional features; not strip them away. Thus you need code based changes to achieve something as such.

Another option is to build your menu using document subscriber available module CB Content, which completely supports substitutions. So you could do the substitution above to show a menu link to ONLY guests. This would give you exactly what you're wanting without changing template code and without additional modules. Example of this as follows.

[code:1]
<ol>
<li><a href="index.php?option=com_comprofiler&task=userProfile">View Profile</a></li>
[cb:if user="#displayedOrMe" user_id="0"]<li><a href="index.php?option=com_comprofiler&task=registers">Register</a></li>[/cb:if]
</ol>
[/code:1]

The above example would always show the View Profile link, but only show the Register link to those not logged in.

can this not be achieved inside of CSsubs?

No it can not be done within CBSubs.

Now that you've read the above and understand substitutions and their usage in the CB Content module you can use CBSubs Fields to change a fields (preferably Read Only field) value based on subscription. Say I subscribe and this changes cb_subscriptions to 1. I can then use this in a substitution inside CB Content to show a new menu link such as the example below.

[code:1]
<ol>
<li><a href="index.php?option=com_comprofiler&task=userProfile">View Profile</a></li>
[cb:if cb_subscriptions="1"]<li><a href="index.php?option=com_content&task=view&id=32">Thank You for Subscribing</a></li>[/cb:if]
</ol>
[/code:1]

The above would always show the "View Profile" link, but only show the "Thank You for Subscribing" link to those whose field cb_subscriptions equals 1.

Post edited by: krileon, at: 2010/03/22 15:13


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

14 years 3 weeks ago #127607 by jakobe75
Replied by jakobe75 on topic Re:Hide menu item when logged in
@ chuckbone

Your suggestion that CBsubs does not do this led me to google.

Where I found this...
(..is this what you were trying to tell me?)


<?php
// Get the user object
$user = &JFactory::getUser();
// Now work out the User ID
$userId = $user->get('id');
// Now hide the module if user is logged in
if ($userId == 0) :
// Now we break out of the PHP tags and display the JDOC tag to include the module
?>
<jdoc:include type="modules" name="public-position" style="xhtml" />
<?php endif; ?>



but this line confuse me
<jdoc:include type="modules" name="public-position"


What would mine be? if my tab is called Welcome Tab?
this?

<jdoc:include type="tabs" name="Welcome Tab"



and which template file should I add this too?

the main joomla template index
the index in componant.com_profiler/index.php

or component/com_profiler/plugin/templates/praisebuilder/index.php

Please Log in to join the conversation.

14 years 3 weeks ago #127609 by jakobe75
Replied by jakobe75 on topic Re:Hide menu item when logged in
@ Krileon

Thanks, that was a bit more clear.

giving it a try right now.

I need to hide:

- "Join Now" module banner
- a "welcome unregistered user tab"
- a menu item that says "Join Now"

So what you are saying is that, A TAB CANNOT be hidden in any way from a logged user and available to ONLY a public user...?

but a FIELD can be.
and then just include this field on the first tab a logged users normally sees? and modify its value in the cb subs plan.


however
This doesnt work for me, as my first tab that a user sees is not available in the drop down.(it is a Superactivity tab).

When the user logs in this is the first tab they see, no way around this.

thanks for the input, this helped with my modules and menu items but had no effect on the tab issues.

I am other suggestions to hide a tab.

Post edited by: jakobe75, at: 2010/03/22 16:48

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.238 seconds

Facebook Twitter LinkedIn