Yii Framework Forum: 如何在yii2-twig模板中使用use - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

如何在yii2-twig模板中使用use Rate Topic: -----

#1 User is offline   klgd 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 07-November 10

Posted 30 July 2015 - 09:41 AM

我自定义了一个helpers类:app/helpers/SiteHelper
namespace app\helpers;

use Yii;
use app\models\Config;

class SiteHelper
{

    /**
     * 获取title
     * @param string $title
     * @return string
     */
    public static function getTitle($title = '')
    {
        $sitename = Config::getConfigValue('site_name') ? : Yii::$app->name;
        return $title ? $title . ' - ' . $sitename : $sitename;
    }
}


在layout模板main.twig中定义:
{{ use('/app/helpers/SiteHelper') }}

但是使用
{{ SiteHelper.getTitle(this.title) }}

却没有作用,是不是我用错了?到底该如何使用use呢?
0

#2 User is offline   klgd 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 07-November 10

Posted 31 July 2015 - 07:35 PM

谁来帮忙指导一下啊
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users