Invenzzia »

Pages: [1]   Go Down
  Print  
Author Topic: OPTv2: How to load a template file for other folder than the configured  (Read 743 times)
Description: How to i load a template file for other folder than the configured folder.
0 Members and 2 Guests are viewing this topic.
amichelin
User

Offline Offline

Posts: 10


View Profile
« on: April 28, 2009, 19:46:19 »

Hi :

Code:
$tpl = new Opt_Class;

// Loading from array
$cfg = array( 'sourceDir' => '../comun/tpl' );

$tpl->loadConfig($cfg);

$tpl->setup();

$moduleView = new Opt_View('../sales/tpl/news.tpl'); --> this is valid

// Let's assume that the news are loaded from the ORM.
$moduleView->news = ORM::selectNews();
 
$layoutView = new Opt_View('layout.tpl');
$layoutView->title = 'Index';
 
// Assign the module view to the layout
$layoutView->module = $moduleView;
 
// Add some global data for the templates.
Opt_View::assignGlobal('website', array(
    'title' => 'My Website',
    'address' => 'http://www.example.com/'
));



Is valid pass the path to the Opt_View constructor?

Or exist and other code to do this?

Thanks in advance
Logged
Zyx
Your programmer
Administrator
User
*****
Offline Offline

Posts: 291



View Profile WWW
« Reply #1 on: April 28, 2009, 19:52:20 »

../ should not be used in the template names, as it may cause problems with the compiled templates. Even if it works now, I cannot guarantee I will in the future. However, the directory names themselves are acceptable. For example, the OPT port for Zend Framework by default assumes that the template for the specified action in the controller lies in controller/action.tpl template within the sourceDir directory.

Furthermore, you may always specify more paths in sourceDir:

Code:
$tpl->sourceDir = array(
  'file' => './directory1/', // the default directory
  'foo' => './directory2/',
  'bar' => './directory3/'
);
$tpl->setup();

$view1 = new Opt_View('abc.tpl'); // taken from the "file" directory
$view2 = new Opt_View('foo:abc.tpl'); // taken from the "foo" directory
$view3 = new Opt_View('bar:abc.tpl'); // taken from the "bar" directory

Take also the look at http://forums.invenzzia.org/index.php/topic,102.0.html if you need more advanced solutions.
Logged

PozDrX, Zyx
---Invenzzia group---
amichelin
User

Offline Offline

Posts: 10


View Profile
« Reply #2 on: April 28, 2009, 20:18:34 »

Thanks a lot.

Each module has her own folder tpl that holds the tpl files.
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Subject Started by Replies Views Last post
OPTv2: Widoczny prolog w trybie debug i blad wyswietlania strony bez niego. gorky_park 1 598 Last post October 30, 2009, 11:39:13
by Zyx
abercrombie, led to artificially promote sustainable development galardef 0 49 Last post April 16, 2012, 04:26:25
by galardef
OPL for Zend Framework ersonic 1 274 Last post March 09, 2011, 21:27:24
by Zyx
OPT 2 - problem z nagłowkami http / sesje zeus 11 2328 Last post May 20, 2009, 19:04:35
by Agares
OPTv2: Znak   zamieniany na krzaczki. mrKrecik 12 4729 Last post November 19, 2010, 08:11:24
by Zyx