Hello this is definitely something stupid since it has to be possible but I can't seem to find a solution
My page city.htm
title = "city"
url = "/data/:countryslug/:cityslug"
layout = "default"
is_hidden = 0
[cities]
==
function onEnd()
{
$this->page->title = $this->page['var']->name; //test 1
$this->page->title = $this->page['var']; //test 2
}
==
{% set city = cities.getCity %}
twig code
my cities component
public function onRender()
{
// This code will be executed before the default component
// markup is rendered on the page or layout.
$this->page["var"] = $this->city->name; //wont' work
$this->page["var"] = "test" // test 2,doesn't work either
}
public function getCity()
{
//check if city exists, with the slug country
$city = City::with("data.type", "data.datalist")
->where("slug", $this->param("cityslug"))
->whereHas('country', function ($query) {
$query->where('slug', $this->param("countryslug"));
})->first();
if (!$city){
echo "City not found";
}
$this->page["var"] = $city // not working
return $this->city = $city;
}
However $this->page["var"] seems to be inaccessible in the code section of the page. It's written in the documentation it can be accessed like this :\
The properties of a page can be accessed in the PHP code section, or Components by referencing $this->page.
Either I'm calling it at the wrong time or with the wrong variable name. What I'm trying to do is set the title of the page based on the component output and that output must come from any methods in that component not just from getCity() in this case. Also shouldn't October/PHP throw an error when variables don't exist?