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!
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!
Hi,
thanks for your feedback.
Where i have to put the code in the controller?
At the moment i get an error.
thanks for your feedback.
Where i have to put the code in the controller?
At the moment i get an error.
You need to include this line on the top of your block type controller, below the namespace:
Then you can do:
use Concrete\Core\Block\View\BlockView as View;
Then you can do:
$view = View::getInstance() $themePath = $view->getThemePath();
Hi,
there is still an error.
I put your code in the controller of the block.
The block is inside the theme package.
Any idea?
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?
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.
Sorry, but tried this also before. No success
ParseError
syntax error, unexpected '$themePath' (T_VARIABLE) ...
ParseError
syntax error, unexpected '$themePath' (T_VARIABLE) ...
Put a semicolon after
Like this:
$view = View::getInstance()
Like this:
$view = View::getInstance();
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
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
Try this:
Then you can access the theme path in all methods like 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;
Hi,
it does not work, but it helps a lot. I will have a look at this.
Thanks!!!
it does not work, but it helps a lot. I will have a look at this.
Thanks!!!
Hi jakobfuchs,
first thanks, this has been quite helpful.
For future readers, is the error in this last code snippet a missing $ in shouldn't it be
Thanks again,
Sean
first thanks, this has been quite helpful.
For future readers, is the error in this last code snippet a missing $ in
$this->themePath
$this->$themePath
Thanks again,
Sean
Doing this in the block view template should also be possible: