get Theme path in block controller

Permalink
Hi,

we want to use a block inside a package theme.
Now we need to hardcode some links. Is there a soltuon to get the current theme path which we can use in the block controller?

Thanks!

 
jakobfuchs replied on at Permalink Reply
jakobfuchs
Preferably you do this:

$view = View::getInstance();
$themePath = $view->getThemePath();


Doing this in the block view template should also be possible:

$themePath = $this->getThemePath();
Vuish replied on at Permalink Reply
Hi,

thanks for your feedback.
Where i have to put the code in the controller?
At the moment i get an error.
jakobfuchs replied on at Permalink Reply
jakobfuchs
You need to include this line on the top of your block type controller, below the namespace:

use Concrete\Core\Block\View\BlockView as View;


Then you can do:

$view = View::getInstance()
$themePath = $view->getThemePath();
Vuish replied on at Permalink Reply
Hi,

there is still an error.
I put your code in the controller of the block.
The block is inside the theme package.

use Concrete\Core\Block\BlockController;
use Core;
....
use Concrete\Core\Block\View\BlockView as View;
class Controller extends BlockController
{ 
$view = View::getInstance()
$themePath = $view->getThemePath();
...


Any idea?
jakobfuchs replied on at Permalink Reply
jakobfuchs
You need to put the code inside the method where you are going to use it, the view() or on_start() method, for example. You can't put random code inside a PHP class.
Vuish replied on at Permalink Reply
Sorry, but tried this also before. No success

ParseError
syntax error, unexpected '$themePath' (T_VARIABLE) ...
jakobfuchs replied on at Permalink Reply
jakobfuchs
Put a semicolon after
$view = View::getInstance()

Like this:
$view = View::getInstance();
Vuish replied on at Permalink Reply
I didn't see such little issue!
It works now. Now need this variable in different functions.
Did i have to place it in edit function and view function or can i create a global variable?
Thanks
jakobfuchs replied on at Permalink Reply
jakobfuchs
Try this:
class Controller extends BlockController
{
  protected $themePath;
  public function __construct()
  {
        parent::__construct();
        $view = View::getInstance();
        $this->themePath = $view->getThemePath();
  }
}


Then you can access the theme path in all methods like this:
$this->themePath;
Vuish replied on at Permalink Reply
Hi,

it does not work, but it helps a lot. I will have a look at this.
Thanks!!!
SeanDevoy replied on at Permalink Reply
Hi jakobfuchs,

first thanks, this has been quite helpful.
For future readers, is the error in this last code snippet a missing $ in
$this->themePath
shouldn't it be
$this->$themePath


Thanks again,
Sean