php - cakephp 3.0.x extending view? -


i'm using cakephp 3.0.x , wanna make page has multiple views in it. e.g. if have these index.ctp other templates below

  • template/customers/index.ctp
  • template/orders/index.ctp

i want make page template/main/index.ctp. contains index.ctp customers , orders. essentially, views in view (view-ception :p ). possible? if so, how?

yes can if use view elements.

the best way create element template customers index template , output in both customers/index , main/index templates this:-

// output template/element/customers.ctp echo $this->element('customers'); 

the element template inherit variables calling template, can pass variables it. example, if need have $data variable have set in controller $customers:-

echo $this->element('customers', ['data' => $customers]); 

if rather create actual element view template want reuse existing customers/index template can still output using $this->element() in main/index template:-

// output template/customers/index.ctp echo $this->element('../customers/index'); 

personally i'd avoid doing , opt first example , modify existing customers/index use element make code more maintainable in future.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -