Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Am I calling this function correctly?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
sebix7
Smarty Rookie


Joined: 15 Jan 2021
Posts: 5

PostPosted: Wed Jan 20, 2021 8:29 pm    Post subject: Am I calling this function correctly? Reply with quote

redirect function does not work. I have a syntax error?

Code:

{if count($results['posts']) == 1 and $totalResults == 1}

    {foreach $results['users'] as $user}

        {redirect("/".$user['user_name'])}
           
    {/foreach}

{/if}


I'm noob in Smarty.
Back to top
View user's profile Send private message
bsmither
Smarty Elite


Joined: 20 Dec 2011
Posts: 322
Location: West Coast

PostPosted: Fri Jan 22, 2021 1:26 am    Post subject: Reply with quote

I think {redirect} is not a Smarty command. Nor is it a PHP command.

Because Smarty does not know what this is, Smarty stops and complains.
Back to top
View user's profile Send private message
sebix7
Smarty Rookie


Joined: 15 Jan 2021
Posts: 5

PostPosted: Fri Jan 22, 2021 3:54 pm    Post subject: Reply with quote

bsmither wrote:
I think {redirect} is not a Smarty command. Nor is it a PHP command.

Because Smarty does not know what this is, Smarty stops and complains.


Actually "redirect()" is a function I created. What I want to know is if that is the correct way to call a function.

Code:
{function_name(...)}
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Fri Jan 22, 2021 5:27 pm    Post subject: Reply with quote

https://www.smarty.net/docs/en/language.syntax.functions.tpl
Back to top
View user's profile Send private message
bsmither
Smarty Elite


Joined: 20 Dec 2011
Posts: 322
Location: West Coast

PostPosted: Fri Jan 22, 2021 5:52 pm    Post subject: Reply with quote

Functions, Classes, Global Variables, and Constants created/declared in the script cannot be used directly by name in Smarty template code.

Smarty provides an indirect way to access the server request variables and constants declared in the PHP script:
https://www.smarty.net/docs/en/language.variables.smarty.tpl

Smarty will also allow use of PHP's own functions.

For statically-accessible Classes and Objects created/declared in scripts, one must first "register" them with Smarty.
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Fri Jan 22, 2021 7:30 pm    Post subject: Reply with quote

bsmither wrote:
Functions, Classes, Global Variables, and Constants created/declared in the script cannot be used directly by name in Smarty template code.

Code:
{$var|print_r:true}
Back to top
View user's profile Send private message
sebix7
Smarty Rookie


Joined: 15 Jan 2021
Posts: 5

PostPosted: Fri Jan 22, 2021 10:32 pm    Post subject: Reply with quote

Got it. Thanks to both of you.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP