|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
sebix7 Smarty Rookie
Joined: 15 Jan 2021 Posts: 5
|
Posted: Wed Jan 20, 2021 8:29 pm Post subject: Am I calling this function correctly? |
|
|
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 |
|
bsmither Smarty Elite
Joined: 20 Dec 2011 Posts: 322 Location: West Coast
|
Posted: Fri Jan 22, 2021 1:26 am Post subject: |
|
|
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 |
|
sebix7 Smarty Rookie
Joined: 15 Jan 2021 Posts: 5
|
Posted: Fri Jan 22, 2021 3:54 pm Post subject: |
|
|
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 |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
|
Back to top |
|
bsmither Smarty Elite
Joined: 20 Dec 2011 Posts: 322 Location: West Coast
|
Posted: Fri Jan 22, 2021 5:52 pm Post subject: |
|
|
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 |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Fri Jan 22, 2021 7:30 pm Post subject: |
|
|
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 |
|
sebix7 Smarty Rookie
Joined: 15 Jan 2021 Posts: 5
|
Posted: Fri Jan 22, 2021 10:32 pm Post subject: |
|
|
Got it. Thanks to both of you. |
|
Back to top |
|
|
|
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
|