【问题标题】:Prestashop set a smarty variable on a hookPrestashop 在钩子上设置了一个 smarty 变量
【发布时间】:2021-03-10 10:17:58
【问题描述】:

我想在钩子actionAuthentication 上分配一个 smarty 变量,当用户成功连接时触发该变量,并在用户断开连接时取消设置。

所以我可以根据以下条件管理我的内容:

        <ul id="menu">
            <li>
                <p>Name :</p>
                {if $my_variable}
                    <span class="employee-name">{$my_variable}</span>
                {else}
                    <span class="employee-name">Firstname Lastname</span>
                {/if}
            </li>
        </ul>

如何从钩子中分配一个全局 smarty 变量?

以下是我尝试过但不起作用的方法:

public function hookActionAuthentication()
{

  $result = 'Myself';

  $this->context->smarty->assign([
      'my_variable' => $result
  ]);
}

【问题讨论】:

  • 客户认证成功后触发该钩子。首先你需要检查你的钩子是否被触发。我的意思是函数内部的一些 die 或 echo 语句,以确保调用你的函数。

标签: prestashop smarty


【解决方案1】:

你不需要使用 hookActionAuthentication($params),你应该分配 $this->context->customer->fistname。 '.$this->context->customer->lastname. 您可以使用函数 isLogged 来检查客户是否已登录

$this->context->customer->isLogged()

【讨论】:

    猜你喜欢
    • 2021-09-08
    • 1970-01-01
    • 2013-06-21
    • 1970-01-01
    • 2011-05-18
    • 1970-01-01
    • 2017-06-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多