How do I add the site name to my theme?

Permalink 2 users found helpful
I know how to do it in previous versions, but that doesn't work in 5.7 so how do I do it now?

 
Responsive replied on at Permalink Reply
Responsive
Dashboard > system&settings > site name
Evert replied on at Permalink Reply
Thanks, but that's not what I meant. I meant adding it to my theme in code.

Like in previous versions of Concrete5 I could do this:

<?php  
               $block = Block::getByName('My_Site_Name');  
               if( $block && $block->bID ) $block->display();   
               else echo SITE;
?>


But if I do that now I get an error, so I guess it works differently now.
hissy replied on at Permalink Best Answer Reply
hissy
$site = Config::get('concrete.site');
echo $site;
linuxoid replied on at Permalink Reply
linuxoid
If I put this into my view.php, it works, I get the site name.

If I put this into my block controller.php, it throws a "syntax error, unexpected '(', expecting ',' or ';' "

How come?

How can I get the Site Name in the controller?

Thanks.
Evert replied on at Permalink Reply
Can you copy-paste that line in your code plus 3 lines before and 3 lines after it?
Syntax error means that you wrote something that is completely invalid to the parser, so you probably misplaced some character.
linuxoid replied on at Permalink Reply
linuxoid
If I do this:
public $email_to = '';
   public $site_name = '';
   public $email_subject = 'Question from site %s';
   public $wait_time = 60;
   public function add() {
      $this->createTable();
   }
everything's fine.

If I do this:
public $email_to = '';
   public $site_name = Config::get('concrete.site');
   public $email_subject = 'Question from site %s';
   public $wait_time = 60;
   public function add() {
      $this->createTable();
   }
I've got that error.

If I put
$site = Config::get('concrete.site');
echo $site;
in the view.php, it shows the site name alright.
Evert replied on at Permalink Reply
Ah yes, you get that error, because that line is not allowed there. Only static stuff like a string or a number is allowed there, not dynamic stuff like function calls. Change it to this:

public $email_to = '';
   public $site_name;
   public $email_subject = 'Question from site %s';
   public $wait_time = 60;
   public function __construct() {
      $this->site_name = Config::get('concrete.site');
   }
   public function add() {
      $this->createTable();
   }
linuxoid replied on at Permalink Reply
linuxoid
Something's wrong here. Without this site name code, everything works fine, in particular while adding the block, the database gets updated. As soon as I insert that site name thing:
public $email_to = '';
   public $site_name = '';
   public $email_subject = 'Question from site %s';
   public $wait_time = 60;
   public function __construct() {
       $this->site_name = Config::get('concrete.site');
   }
   public function add() {
      $this->createTable();
   }
   public function save($args)
   {
      $args['email_to'] = isset($args['email_to']) ? trim($args['email_to']) : '';
      $args['site_name'] = isset($args['site_name']) ? trim($args['site_name']) : '';
      $args['email_subject'] = isset($args['email_subject']) ? trim($args['email_subject']) : '';

first, it stops loading the email from the DB, and can't save anything to the DB with this error:
An exception occurred while executing 'select * from MyForm where bID=': SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1
linuxoid replied on at Permalink Reply
linuxoid
I'm trying to add an admin user name or email address
use UserInfo;
...
$adminUserInfo=UserInfo::getByID(USER_SUPER_ID);
$this->email_to = $adminUserInfo->getUserEmail();
or this:
$u = new User();
$ui = UserInfo::getByID($u->getUserID());
$this->email_to = $ui->getUserEmail();

And I get the same error: syntax error, unexpected '(', expecting ',' or ';'

I've got that code from the system Form block. How come it works with the system block, but nothing works in my own block?
Evert replied on at Permalink Reply
I'm not sure what's going wrong now. And I prefer working on my own things now so I won't dive into this question anymore. I hope you'll find someone who can help you. :-)