php - Laravel - Modify and return variable from @include -
i'm including multiple templates in loop using
@include('template.included')
before including template define
$page = 0;
and inside template, multiple times calls
$page++;
inside included template, value correctly increments, outside template seems $page variable stays same - it's looking @include creates it's own copy of each var use.
i need $page variable update inside templates, , have it's value returned main template - missing simple?
appreciate suggestions!
edit:
my issue, example:
$page = 0; @include('template.included') //this calls $page++ 5 times echo $page; //returns 0
i need $page return 4, not 0
your assumption correct, laravel's view system creates new scope each view loads. illuminate\view\factory::make()
method used when including views, this:
new view($this, $this->getenginefrompath($path), $view, $path, $data)
it's creating new view , passing data it, means it's sending copy of information. since arguments there not passed reference (which deprecated , in newer php versions removed), want can't done.
that being said, approach seems flawed. looks me you're building pagination in view, should not doing there. laravel offers easy way create pagination, should perhaps that.
Comments
Post a Comment