how to use a controller variable in a php code block
Permalink
I'm sorry to ask this beginner's question. I just can't figure it out myself with only the documentation.
I have a single page with its view at /application/single_pages/zzztest/view.php
I have set up a controller at /application/controllers/single_page/zzztest.php
In the controller I have set a variable to be used in the view.php directly as well as through a Php-code-block that I've put in this single page.
the variable shows up in the view.php, but i can't use it from within the Php-code block.
How should I treat this variable in the controller so that the code in the Php-code block reads this variable?
in /application/single_pages/zzztest/view.php:
this works: I can see the contents of the zzz-variable, which has been set in the controller:
controller: /application/controllers/single_page/zzztest.php:
the php in the Php code block that I've added on this single page:
This last variable is not visible.
What do I have to do in order to make the variable from the single page controller active in the Php code block on this single page?
C5 v8.5.5.
I have a single page with its view at /application/single_pages/zzztest/view.php
I have set up a controller at /application/controllers/single_page/zzztest.php
In the controller I have set a variable
$zzz
the variable shows up in the view.php, but i can't use it from within the Php-code block.
How should I treat this variable in the controller so that the code in the Php-code block reads this variable?
in /application/single_pages/zzztest/view.php:
<!-- other code --> <div> test is: <?php echo $zzz; ?> </div> <!-- other code-->
this works: I can see the contents of the zzz-variable, which has been set in the controller:
controller: /application/controllers/single_page/zzztest.php:
<?php namespace Application\Controller\SinglePage; use Concrete\Core\Page\Controller\PageController; class Zzztest extends PageController { public function view() { $this->set('zzz', 'TESTzzz'); } }
the php in the Php code block that I've added on this single page:
<div> test is: <?php echo $zzz; ?> </div>
This last variable is not visible.
What do I have to do in order to make the variable from the single page controller active in the Php code block on this single page?
C5 v8.5.5.
Hi, the page 'dies' as expected. see screenshot.
I now added a php-isset check to both the view.php and the code in the php-code block, with the same result: the variable is not recognised in the php code block:
view.php:
and the code in the php-code block on that same single page:
Could it be possible that the php code block or my theme unsets the variable? Should I do something else when I want that a controller -variable is available also for the blocks (in Areas) on that page? Should I declare them globally or something like that?
Thanks!
I now added a php-isset check to both the view.php and the code in the php-code block, with the same result: the variable is not recognised in the php code block:
view.php:
and the code in the php-code block on that same single page:
Could it be possible that the php code block or my theme unsets the variable? Should I do something else when I want that a controller -variable is available also for the blocks (in Areas) on that page? Should I declare them globally or something like that?
Thanks!
Often the problem is the finicky path and class names don't relate in the way the core expects and the view runs without a controller.