Undefined variable $c in single page

I have run into this weird little issue and want to ask if anyone else has seen it.

I have a built a multilanguage page with the latest release (9.3.8) and the “page_forbidden” single-page template does not seem to receive a $c variable from the controller.

When access a “wrong” page, I get the error message instead of either the original singlepage or any template I place into the singlepage folder. Shouldnt it work out of box?

Or did I manage to mess it up myself and dont know how?

Anyone can confirm?

Thanks!

I think it should be available. I just checked a theme that has a custom single page for page_forbidden and although $c is not used on the page, it is used in the included elements and it renders fine.

You might check what is getting passed into the elements when they are being called from the single page context - that might shed some light - I don’t think elements naturally have access to $c because they’re just kinda standalone components that get variables pipe into them for use is my understanding.

1 Like

Hi,

I have the same problem.
I created a “route” in application/boostrap/app.php and insert this code

Route::register('/offre-emploi-medical/{offerId}', 'Application\Controller\OffreDetailController::view');

Then I created a controller in applications/controllers/offre_detail_controller.php in which I’m using the view by specifying my theme like this

$view = new View('/offre_detail');
$view->setViewTheme('duosante');
$view->setController($this);
$this->set('jobDetail', $jobDetail);
return $this->responseFactory->view($view);

Then I have my view file in application/views/offre_detail.php with my HTML. This HTML is inserted into my theme’s view.php using <?php echo $innerContent;?>

Unfortunately I have lots of problems with the display with the error:
Undefined variable $c.

Why is $c not initialized in this configuration? And how to initialize it?

Thanks,

Try with

$c = \Concrete\Core\Page\Page::getCurrentPage();

Hi,

I always have this error ‘Undefined variable $c’.

You have to place

$c = \Concrete\Core\Page\Page::getCurrentPage();

in the view file.

As an alternative, you can place this code right after $this->set('jobDetail', $jobDetail);:

$this->set('c', \Concrete\Core\Page\Page::getCurrentPage());

I tried that too but it still doesn’t work. It seems this is not possible according to Nour who saw it in the documentation.

Following this code, it seems you are creating totally custom controller.
So by design, it’s not connected to any “Page”/“Single page” in CMS.
Hence you can’t access $c variable.

Is it for fetch/ajax call? You would need to pass page id in url like:

Route::register('/offre-emploi-medical/{pageId}/{offerId}', 'Application\Controller\OffreDetailController::view');

and then just create $c using passed id

$c = Page::getById($pageId);