Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Smarty {if} statement to check if user is logged in

Hi guys, i cant seem to find a documentation, if i put a smarty code inside the .tpl template, what's the syntax of doing so?

example:

**inside default.master.tpl i'd like to have something visitors(not logged in users) to see

{if not $User="loggedin"}
<show this to the logged in >
{/if}

Comments

  • grep is your friend.

  • KasperKasper Scholar of the Bits Copenhagen Vanilla Staff

    For a list of all Smarty variables, enable debug mode: {debug}

    Kasper Kronborg Isager (kasperisager) | Freelance Developer @Vanilla | Hit me up: Google Mail or Vanilla Mail | Find me on GitHub

  • phreakphreak Vanilla*APP (White Label) & Vanilla*Skins Shop MVP

    @kasper: I know this thread is not the newest but i have a question about it.

    The Smarty Tags work for the mobile version under 2.0.18.10, but not under the desktop theme. Any ideas why this could be the reason?

    Thanx

    • VanillaAPP | iOS & Android App for Vanilla - White label app for Vanilla Forums OS
    • VanillaSkins | Plugins, Themes, Graphics and Custom Development for Vanilla
  • KasperKasper Scholar of the Bits Copenhagen Vanilla Staff

    Which tags specifically?

    Kasper Kronborg Isager (kasperisager) | Freelance Developer @Vanilla | Hit me up: Google Mail or Vanilla Mail | Find me on GitHub

  • phreakphreak Vanilla*APP (White Label) & Vanilla*Skins Shop MVP
    edited January 2014

    {if $User.SignedIn}{/if} works for me in the mobile theme but not the desktop?

    I guess i should try with: {if $User="loggedin"} ?

    • VanillaAPP | iOS & Android App for Vanilla - White label app for Vanilla Forums OS
    • VanillaSkins | Plugins, Themes, Graphics and Custom Development for Vanilla
  • KasperKasper Scholar of the Bits Copenhagen Vanilla Staff

    Try adding {debug} and let me know what it spits out

    Kasper Kronborg Isager (kasperisager) | Freelance Developer @Vanilla | Hit me up: Google Mail or Vanilla Mail | Find me on GitHub

  • vrijvlindervrijvlinder Papillon-Sauvage MVP

    Is your desktop theme tpl? or php ?

  • ShadowdareShadowdare r_j MVP
    edited January 2014

    $User.SignedIn should work, so you should take a look at the {debug} output that Kasper mentioned.

    In Vanilla 2.0.18.10, the default master template is a PHP file.

    If the theme's view file is a PHP file, you can check the user's logged in status with:

    <?php
    if(Gdn::Session()->IsValid())
    {
       echo "Signed in.";
    }
    ?>
    

    If the theme's view file is a TPL file, please try the user name variable to see if it works:

    {if $User.Name}Signed in.{/if}
    {if !$User.Name}Not signed in.{/if}
    

    Add Pages to Vanilla with the Basic Pages app

  • phreakphreak Vanilla*APP (White Label) & Vanilla*Skins Shop MVP
    edited January 2014

    Thank you for your help @Shadowdare. That was, what i was looking for. :)

    Wonder if there is a reason why this is not managed the same way for both template options (desktop and mobile).

    • VanillaAPP | iOS & Android App for Vanilla - White label app for Vanilla Forums OS
    • VanillaSkins | Plugins, Themes, Graphics and Custom Development for Vanilla
  • vrijvlindervrijvlinder Papillon-Sauvage MVP
    edited January 2014

    It could be it is matter of choice, you can use a php based mobile theme too along with your desktop php theme. Or you can use both tpl based themes, or use the embed friendly tpl or php.

    It is about what you want to use. Either or is good.

Sign In or Register to comment.