This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

abbasadel
abbasadel

Hi,

I have a partial with a parameter and I want to access this parameter on the partial OnStart() function like this:

{% partial 'mypartial' count='10' %}

Inside the partial

function OnStart(){
$count = //How to get the value of the variable count?
}

Thanks, Abbas

PMK
PMK

Does somebody have an answer?

Tschallacka
Tschallacka

$this->property('count'); ?

PMK
PMK

michael8985 said:

$this->property('count'); ?

Returns:

call_user_func_array() expects parameter 1 to be a valid callback, class 'Cms\Classes\Controller' does not have a method 'property'

In class Cms\Classes\Controller.php in function renderPartial() I do see the variables with the values, including the name of the partial.

If I make an "else" state on line number 825, and putting the partial stuff inside the $this->vars array, then I can access it.

if (($partial = Partial::loadCached($this->theme, $name)) === null) {
    ... existing code here ...

} else {
    $this->vars[$name] = $parameters;
}

I think this should be done inside the Controller class via a getter, but if you paste this code here below inside your partial template in the PHP part, it will fix the problem.

$controller = $this->getController();
$partialVars = $controller->vars["your-partial-name-here"];
// var_dump($partialVars);

Github ticket: https://github.com/octobercms/october/issues/1235

Last updated

Douglas Godinho
daftspunky
daftspunky

Log this on GitHub Issues so it receives the appropriate attention

Douglas Godinho
Douglas Godinho

Already have one there! Thank you for your attention! https://github.com/octobercms/october/issues/1235

daftspunky
daftspunky

Setting the variable

{% partial 'mypartial' count='10' %}

Accessing the variable

function onStart()
{
    $count = $this->count;
}

1-8 of 8

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.