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.

convert these tpl tags to php

422422 Developer MVP
edited May 2012 in Vanilla 2.0 - 2.8

I am porting a site for a Vanilla Member .. and the default.master file is tpl.

Ive done most of the conversion, but a little stumped with this ...


     
      
       {if $User.SignedIn}
       
        {$User.Name}
        {if $User.CountNotifications}
         {$User.CountNotifications}
        {/if}
       
       Inbox
        {if $User.CountUnreadConversations}
         {$User.CountUnreadConversations}
        {/if}
       
       {if CheckPermission('Garden.Settings.Manage')}
        Dashboard
       {/if}
        {/if}
        {link path="signinout"}
        {if !$User.SignedIn}
            Apply for Membership
        {/if}
     
    
    
     Download
     Hosting
     Documentation
     Community
     Addons
     Blog
     Home
    
   

I need to make this current with new vb versions ( 2.0.18.4 )
Plus its for the default.master.php version ...

Any ideas.. merely swapping out {if with <?php if .... etc ???

There was an error rendering this rich post.

Answers

  • hbfhbf wiki guy? MVP

    Here's one

    {if $User.Signedin }== if ($Session->IsValid())

  • 422422 Developer MVP

    Okies awesome.. Gonna have to go thru it a line at a time lol.

    There was an error rendering this rich post.

  • hbfhbf wiki guy? MVP

    422 said:
    Okies awesome.. Gonna have to go thru it a line at a time lol.

    if i free up some time i can give it a run through.. i have all of that code in plguins already written..

  • 422422 Developer MVP

    Would appreciate tat thankyou :) no rush.

    There was an error rendering this rich post.

  • hbfhbf wiki guy? MVP

    no warranties, guarantees or attribution for what snippets were stolen from where...

    
    <?php
    
    //Get the environment
    $Session = Gdn::Session();
    
    //{if $User.SignedIn}
         if ($Sender->Menu && $Session->IsValid()) {
            
           // {$User.Name}
            $Name = $Session->User->Name;
           // {if $User.CountNotifications}
           //  {$User.CountNotifications}
           // {/if}
            $CountNotifications = $Session->User->CountNotifications;
            if (is_numeric($CountNotifications) && $CountNotifications > 0)
                $Name .= ' '.$CountNotifications.'';
    
            if (urlencode($Session->User->Name) == $Session->User->Name)
                $ProfilePath = $Session->User->Name;
            else
                $ProfilePath = $Session->UserID.'/'.urlencode($Session->User->Name);
            
            $this->Menu->AddLink('User', $Name, '/profile/'.$ProfileSlug, array('Garden.SignIn.Allow'), array('class' => 'UserNotifications'));
    
           
           //Inbox
            //{if $User.CountUnreadConversations}
            // {$User.CountUnreadConversations}
           // {/if}
            
            $Inbox = T('Inbox');
             $CountUnreadConversations = $Session->User->CountUnreadConversations;
             if (is_numeric($CountUnreadConversations) && $CountUnreadConversations > 0)
                $Inbox .= ' '.$CountUnreadConversations.'';
                
             $Sender->Menu->AddLink('Conversations', $Inbox, '/messages/all', FALSE, array('Standard' => TRUE));
           
          // {if CheckPermission('Garden.Settings.Manage')}
          //  Dashboard
          // {/if}
             $this->Menu->AddLink('Dashboard', T('Dashboard'), '/dashboard/settings', array('Garden.Settings.Manage'));
           
          // {link path="signinout"}
             $this->Menu->AddLink('SignOut', T('Sign Out'), SignOutUrl(), FALSE, array('class' => 'NonTab SignOut'));
             }
            
           // {if !$User.SignedIn}
            else
            {
                // Apply for Membership
                $Url = RegisterUrl($this->_Sender->SelfUrl);
                if(!empty($Url))
                    $Sender->Menu->AddLink('Apply', T('Apply for Membership'), $Url));
            }//{/if}
            
            
    /?>
    

    i assumed that all of the tpl was trying to shove stuff into the menu bar... so i called addlink on urrything.

  • If hbf wouldn't have solved it, I would have given this advice:

    In the Smarty Cache directory is all templates converted to PHP maybe it uses a lot of custom PHP in those PHP files, but still... :-) Luckily the code of hbf looks great, as always... :-)

    Normally the {/if} of Smarty are shorthand for the code

    endif;

    and the normal {if} statements are normal if's in PHP. Lots of other things is shortened PHP code, for example {link} is a custom function, so it's tougher to figure out :-)

    There was an error rendering this rich post.

  • 422422 Developer MVP

    hmm still working my way thru it lol.

    There was an error rendering this rich post.

  • 422422 Developer MVP
    edited May 2012
    
                       {if $User.SignedIn}
                           < a href="{link path="profile"}">
                            {$User.Name}
                            {if $User.CountNotifications}
                             < span>{$User.CountNotifications}</ span>
                            {/if}
                           
                           < a href="{link path="messages/inbox"}">Inbox
                            {if $User.CountUnreadConversations}
                             < span>{$User.CountUnreadConversations}</ span>
                            {/if}
                           < /a>
                       {if CheckPermission('Garden.Settings.Manage')}
                            < a href="{link path="dashboard/settings"}">Dashboard</ a>
                       {/if}
                        {/if}
                        {link path="signinout"}
                        {if !$User.SignedIn}
                            < a href="{link path="register"}">Apply for Membership</ a>
                        {/if}
                     
    

    this is driving me bonkers.

    There was an error rendering this rich post.

  • Do it in steps

    {/if} = endif;

    {if !$User.SignedIn} = if ($Session->IsValid())

    {link path=...} = $this->Menu->AddLink(...)

    Let's see what you have left afterwards...

    The CheckPermissions functions is stuffed in the AddLink function, so that's the final step.

    There was an error rendering this rich post.

  • 422422 Developer MVP

    Right will have another go in the mornin. Cheers guys.

    There was an error rendering this rich post.

Sign In or Register to comment.