Opencart meta title include store name

前端 未结 3 1360
半阙折子戏
半阙折子戏 2021-01-28 16:38

How to get the store name when in the Document class. This is what I am trying to do:

public function setTitle($title) {

    // Append store name if small title         


        
3条回答
  •  一生所求
    2021-01-28 17:05

    You cannot use $this->cofig inside document class, because it has not config property, also it has not magic __get method, like controller class.

    You can try to change your header controller.

    public function index() {
    
       $title = $this->document->getTitle();
       if(strlen($title) < 30){
          $this->data['title'] = $title . ' - ' . $this->config->get("store_name");
       } else {
          $this->data['title'] = $title;
       }
    
       // ....
    }
    

    -------- UPDATED --------

    If you want use $config inside Document class, you may use global variable:

    public function setTitle($title) {
    
        global $config;
        // Append store name if small title
        if(strlen($title) < 30){
            $this->title = $title . ' - ' . $config->get("store_name");
        } else {
            $this->title = $title;
        }
    }
    

    But I recommend you don't do this.

提交回复
热议问题