What syntax do I use in “layout editor” (block with smarty support) to check if user logged in?
```php
- Orders
- Wishlist
- Comparelist
{if userlogedin?}
{/if}
```
What syntax do I use in “layout editor” (block with smarty support) to check if user logged in?
```php
{if $auth.user_id}
[quote name='cscartrocks' timestamp='1399353902' post='182971']
{if $auth.user_id}
[/quote]
Works great, thanx…
I add the code to a new block:
{if $auth.user_id}
{__("wishlist")}{if $wishlist_count > 0} ({$wishlist_count}){/if}
{/if}
The wishlist link works, but it does not show the count of wishlist?
What context are you in? Why do you expect $wishlist_count variable to be set? I don't think it's done globally for all pages.
I want to make like this…
[attachment=8149:螢幕快照 2014-06-12 下åˆ2.14.57.png]
Then you'll have to set your $wishlist_count variable.
[quote name='atlaswu' timestamp='1402553896' post='185561']
I want to make like this…
[attachment=8149:螢幕快照 2014-06-12 下åˆ2.14.57.png]
[/quote]
Try {$smarty.session.wishlist.products|count}
[quote name='eComLabs' timestamp='1402644995' post='185667']
Try {$smarty.session.wishlist.products|count}
[/quote]
{if $auth.user_id}
{__("wishlist")}{if $smarty.session.wishlist.products|count > 0} ({$smarty.session.wishlist.products|count}){/if}
{/if}
It's working!! I really appreciate your help.
You are welcome!
Is there a way to access the status that is held in {$auth.user_id}
in a PHP script (obviously on same server!) rather than within Smarty Template?
I already use
{$auth.user_id}
{$user_info.firstname}
{$user_info.lastname}
{$user_info.email}
{$auth.usergroup_ids[2]}
to pull user data into a complex custom form loaded via iframe which is only accessible to logged in users.
What I must achieve to make my new version of this form work, is to be able to dynamically (via ajax) test for user logged in status to enable a 'Save' button.
So, unregistered user can view the form and play with it with disabled/hidden 'Save' button. Then, if they want to save/submit the data they have to login or register (via modal or pop-up window) then they will be able to submit/save the form…
Try
$_SESSION['auth']['user_id']
Not working at first attempt - will persevere… and report back!
correct test would be:
if( !empty($_SESSION['auth']['user_id']) )
Use of {$auth.user_id}
should also work. But if not, using {$smarty.session.auth.user_id}
would do the same and prevent the overhead of any ajax requests.
@tbirnseth
Thank you for that - my reasoning for ajax call is that I do not want the visitor to have to reload the form i.e.
Visitor/User Plays With Form [not logged in/registered] > Visitor then wants to save/submit their input > Link to Log-in/Register [new tab/modal window] > Enable ‘Save/Submit’ Button > Bingo! [Without re-loading form].
I could of course just set a cookie to save the the form values temporarily for non logged in / registered visitor but I would prefer not to do it that way… there is also quite a lot of data / fields in the form…