Here is the page I am testing, and having issues with: https://brookechao.com/hhs-musical/profile-private/jchao/
Basically, I’m created a cast member profile entry for each student and teacher in the musical, as well as a member. We are allowing guests to submit comments based on a entry and form pulling from an individual cast member entry. I am moderating entries as they come in, and also it will be up for about a week to a month tops. It’s just for the musical. The bugaboo is in making it so the template that displays the comments for a specific user/entry is viewable only by a username that matches a value that is also in one of the entry fields (I have played with url_title as well as a custom a “profile_username” field). To determine what info displays on the front end, the private profile template uses three conditionals to check
1) is the user logged out. If so, display a message telling them they need to login to see that page
2 ) is the user logged in, AND parameter in entry (url_title or a specific entry field) matches the logged in username that matches a specific OR if the logged in username is mine (so I can see the page no matter what). If either condition is met, it displays the content related to that entry….specifically comments their main entry has received.
3) is the user logged in, BUT the logged in username matches neither the specified parameter from the entry field, nor does the username match my username. If that’s the case, then they see a message stating that users can only view their own page (using that template).
It seems like the code works okay, but here’s the issue I’m running into, and it’s making it impossible to test accurately. EE seems to be recognizing me as me, even if I’m logged out, or logged in as one of my three test users. I thought I’d test that theory and added a few variable snippets in the body of the page, to see what information was being passed when viewing the page.
It’s puling in my screen_name regardless of whether I’m logged in, logged out, or logged in as a test user. Similarly, it’s pulling in my member_id and username, no matter whether I’m logged in, logged out, or logged in as a test user. BUT, it displays the correct member_group_id, for the account I’m actually logged into, as well as the variable I was using to match username in the entry.
These are the things I’ve tried that have had no effect: 1. Making sure all “cache” options are off in the system settings 2. Logged out and cleared browser cache and browser data 3. Logged out, cleared cache/data and logged in as one of my test users. 4. Logged out, cleared cache, installed a new browser (that’s never had a chance to cache anything), viewed page. 5. Viewed page on cell phone (not on home wi-fi network). 6. Set all user IPs to 0.0.0. (they were all defaulting to the same one…my current IP) 7. Viewed page in anonymous browsing mode 8. Viewed page over VPN. 9. Tried setting url title for entries to match username, so it can compare the two if logged in. 10. Tried setting a custom field (profile_username) to match username, so it could compare the entry’s value for that field, with the logged in username.
All the same results. How on earth is it able to pull in my member_id username and screen_name variables with each of those instances - whether logged in or not. Also, when logged in as a test user, how does it still pull in all that info but somehow still identifies the correct member_group_id, even with all the other info being associated with my SuperAdmin account?
It can’t be a browser cache issue, because of the things I’ve tried. It can’t be related to our internet connection because we’ve gotten the same results over mobile data network (wifi turned off), as well as VPN for a local university. And I do have caching options set to off in the system and template settings.
It sounds as if you are caching EE templates? If so, to get dynamic variables such as currently logged in username etc I normally put those parts in a non-cached embed template. That way the page is cached but the dynamic portion stays dynamic, and you should see correct details.
Not exactly. I have all caching parameters set to off, because the site is almost entirely dynamic, but at somepoint I finally stumbled across the Caching management in utilities. That took care of it. It was so odd, because nothing was set to cache anything. And what felt like days of banging my head against a wall of code, I finally figured out that the conditionals I was using were never going to work. But I did figure out that I could compare the last segment of the dynamic URL against the logged_in_username. Because I was also trying to determine if the person should view that page (logged out….log in….logged in but segment doesn’t match logged_in_username….fugedaboutit, here’s a link to your profile, or you can go back to the main cast list and send someone a lovely fan mail message. LOL
I combined the basic with some additional if then conditionals based on whether or not there were any results for that entry/page. If “no_results” I made sure that they didn’t see the “You have fan mail!” content - which could be sad - or even worse, no content at all. So I made sure there was a “Hey great job {first name}! Thank you so much for your hard work” message that is in the same pretty container I use to enclose each “fan mail” message.
EE continued to produce really strange sporadic issues…displaying everything perfectly, and then suddenly refusing to embed the head include. I basically worked on it from 11:00 last night to about 10 minutes ago, and it’s finally working right. LOL
Thanks for weighing in…I’ll know next time that if nothing else works, just run that cache clearing utility. 😊
Here’s the finished product. All I have to do know is add the rest of the cast and crew to my test entries. LOL Link: Musical fan mail page
Glad you got it sorted! I can only assume some templates might have been cached at some point? Clearing the cache can sometimes correct things as you found.
Yes conditionals can sometimes take a bit of head scratching to get right, especially if you’re evaluating lots of things. Add to that you can often do conditionals in different ways to get the same result!
Like your approach of using no_results
as fallback content, I use that quite often, seems like you were “thinking out side the box” on that one.
Nice site, clean, does what it says on the tin 😊
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.