|
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 |
Pat07 Smarty Rookie
Joined: 21 Jun 2019 Posts: 6
|
Posted: Fri Jun 21, 2019 12:44 pm Post subject: redirect and back |
|
|
Hi there.
I am new to smarty and I tried to ste a few lines of code in Prestashop.
Code: | Tools::redirect('index.php?controller=authentication?back=$link->getCMSLink(29)') |
Here is my problem the value of 'back' seems to not work but I can't understand why...
Any help would be much appreciate.
Thanks ! |
|
Back to top |
|
bsmither Smarty Elite
Joined: 20 Dec 2011 Posts: 322 Location: West Coast
|
Posted: Sun Jun 23, 2019 12:26 am Post subject: |
|
|
I don't know Prestashop, so I don't have the context of what you are trying to do ("I tried to ste a few lines of code" - I can't guess what 'ste' is), nor where this statement comes from: PHP code or source template text.
But if this statement is within a template file that Smarty populates with data, and if $link is a Smarty variable (doesn't look like it is) holding a multi-dimensional array, then the template syntax should be:
{$link.getCMSLink.29}
A slightly different template syntax might be:
{$link.getCMSLink[29]}
The braces are important. |
|
Back to top |
|
Pat07 Smarty Rookie
Joined: 21 Jun 2019 Posts: 6
|
Posted: Mon Jun 24, 2019 1:49 pm Post subject: |
|
|
Thanks for the answer and your help!
Actually the code is in cms.tpl file.
Here is a bit more of the context
Code: | {if $logged}
<div class="rte{if $content_only} content_only{/if}">
{hook h='libreecoute'}
</div>
{else}
<div class="rte{if $content_only} content_only{/if}">
{Tools::redirect('index.php?controller=authentication?back=$link->getCMSLink(29)')}
</div>
{/if} |
I tried with
{$link.getCMSLink.29}
or
{$link.getCMSLink[29]}
but it failed to work... |
|
Back to top |
|
bsmither Smarty Elite
Joined: 20 Dec 2011 Posts: 322 Location: West Coast
|
Posted: Mon Jun 24, 2019 3:57 pm Post subject: |
|
|
I see.
Then this:
Code: | {Tools::redirect('index.php?controller=authentication?back=$link->getCMSLink(29)')} | is asking Smarty to use the redirect() method in the static Tools class. This can work. (See: https://www.smarty.net/forums/viewtopic.php?t=16608&highlight=classes) But the argument also appears to be a method of a class.
So, is $link a Smarty variable, or is this an attempt at accessing an instantiated class being held in the PHP variable $link?
*I think*, even though the Smarty documentation says Smarty can work with object syntax (see https://www.smarty.net/docs/en/language.syntax.variables.tpl and note {$foo->bar()}), this assumes that an object has been assigned to the Smarty variable $link. For example in the PHP code:
Code: | $linkManager = new CMS();
$smarty->assign('link',$linkManager); |
I also see:
Code: | {hook h='libreecoute'} | which must be a user-defined plugin or in-template function. |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Tue Jun 25, 2019 10:06 am Post subject: |
|
|
I think, single quotes were an obvious mistake.
Try changing them to
Code: | Tools::redirect("index.php?controller=authentication?back={$link->getCMSLink(29)}") |
|
|
Back to top |
|
Pat07 Smarty Rookie
Joined: 21 Jun 2019 Posts: 6
|
Posted: Wed Jun 26, 2019 8:19 am Post subject: |
|
|
Thanks all for your help.
I failed to make it work so far, but I believe I have a more global problem.
I will try to go on working on that, I get back to tell you if I found any solution.
Thanks again! |
|
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
|