2

I would like to know if it's possible to override on runtime the cachePath defined inside this method:

http://li3.me/docs/lithium/template/view/Compiler::template()

I am trying to use lithium as a multitenant application and I am trying to seperate everything between tenants including compiled templates.

Mauricio Lopez
  • 447
  • 4
  • 12
  • If "path" is defined inside the options it should be used, instead of the default.. if you see at the 3rd line there is $options += $defaults; which adds not existing params but it doesn't override them if they exists.. So if you set path to the options array of the method it will be fine.. – Svetoslav Nov 26 '15 at 15:34
  • Yea, I noticed that @svetlio, but I did a complete lookoout of one request using xdebug, and I know where compile::template() is called but there areLOTS of indirections and I am not sure WHERE I should set the options without actually modifying the litlium core. – Mauricio Lopez Nov 26 '15 at 16:05
  • please post a snippet of code that you have written and doesn't work, or that you'd like to write – Oerd Dec 06 '15 at 12:14

1 Answers1

2

There are lots of ways to do it, depending on your implementation. One way is to set the compiler.path parameter of your html (or other content types) handler in using Media::type function during bootstrap.

For example:

Media::type('html', null, array(
  'cast' => false,
  'view' => 'lithium\template\View',
  'paths' => array(
    'template' => '{:library}/views/{:controller}/{:template}.{:type}.php',
    'layout'   => '{:library}/views/layouts/{:layout}.{:type}.php',
    'element'  => '{:library}/views/elements/{:template}.{:type}.php'
  ),
  'compiler' => array(
    'path' => '/path/to/your/cache/folder'
  )
));

But judging by your requirement, it looks like you're better off extending \lithium\template\view\Compiler class and override the template function.

You can do this by setting the class name of the compiler using the same Media::type function

Media::type('html', null, array(
  'cast' => false,
  'view' => 'lithium\template\View',
  'paths' => array(
    'template' => '{:library}/views/{:controller}/{:template}.{:type}.php',
    'layout'   => '{:library}/views/layouts/{:layout}.{:type}.php',
    'element'  => '{:library}/views/elements/{:template}.{:type}.php'
  ),
  'classes' => array(
    'compiler' => '\namespace\class\name'
  )
));
blubear
  • 431
  • 4
  • 12