Storing template files in sub-directory

646 views
Skip to first unread message

Michael Keplinger

unread,
May 16, 2012, 4:33:56 PM5/16/12
to raintpl
can template files be stored in multiple directories (sub-directories)

index.php
example.php
[tpl]
--> index.html
[other_directory]
----> example.html


This doesn't seem to allow me to call this template with either of
these:

$tpl = new RainTPL;
$tpl->draw('example');
$tpl->draw('other_directory/example');

How can this be done? I have a lot of different template files and
would like to organize them into subdirectories for organization

Rain

unread,
May 16, 2012, 4:46:38 PM5/16/12
to rai...@googlegroups.com
Yes, you can

raintpl::configure( "tpl_dir", "tpl/" );   // set the folder, put a trailing slash in tpl/
$tpl = new raintpl;
$tpl->draw( "index");   // load index from the main folder
$tpl->draw( "subfolder/template");   // load template from the subfolder

Hope this will fix your problem. If doesn't, give us more details about the version you are using and the error on screen.
Thanks

Michael Keplinger

unread,
May 21, 2012, 3:50:23 PM5/21/12
to raintpl
Actually, we have just upgraded to Raintpl 3.0 and this isn't working.

I have set
// namespace
use Rain\Tpl;

// include
include "code/library/Rain/Tpl.php";

// config
$config = array(
"base_url" => null,
"cache_dir" => "cache/",
);

Tpl::configure( $config );
Tpl::configure("content-overviews", "tpl/");

===========

Is this any different for RainTpl 3.0 ??

Thanks!

Federico Ulfo

unread,
May 21, 2012, 3:54:15 PM5/21/12
to rai...@googlegroups.com
Hey Mike,

what is content-overviews? Are you extending the Rain class?

Tpl::configure("content-overviews", "tpl/");

if you're not extending the class you want to configure tpl/ as follow:
Tpl::configure("tpl_dir", "tpl/");

Keep me updated on your issue

Michael Keplinger

unread,
May 21, 2012, 4:19:22 PM5/21/12
to raintpl
thanks again for the super fast reply. content-overviews is just a
sub-directory in my tpl directory

[] tpl
|---> home.html
|--> [] content-overvews
|---> some-other-content.html

I store some other html template files in there and then they get
included in one of two ways
(1) directly in home.html with {include="some-other-content.html"}
(2) or I will draw them directly with $tpl-draw('some-other-
content.html');

so far, I cannot get them to work unless they are in the /tpl
directory only.

So, do I call that configure more than once for different template
directories?

does Tpl::configure("tpl_dir", "tpl/"); get called once
and then I can have as many subdirectories as I want, and Rain will
look for them?


On May 21, 12:54 pm, Federico Ulfo <rainelemen...@gmail.com> wrote:
> Hey Mike,
>
> what is content-overviews? Are you extending the Rain class?
> Tpl::configure("content-overviews", "tpl/");
>
> if you're not extending the class you want to configure tpl/ as follow:
> Tpl::configure("tpl_dir", "tpl/");
>
> Keep me updated on your issue
>
> On Mon, May 21, 2012 at 3:50 PM, Michael Keplinger
> <m...@athleticxtreme.com>wrote:

Federico Ulfo

unread,
May 22, 2012, 9:59:58 AM5/22/12
to rai...@googlegroups.com
you configure the settings once for all templates so no need to call Tpl::configure("tpl_dir", "tpl/"); again. We'll check the code within today!
Thanks

Rain

unread,
May 24, 2012, 5:58:17 PM5/24/12
to rai...@googlegroups.com
Hi Michael,
we checked your issue and it was actually a bug, that we fixed in this commit:
https://github.com/rainphp/raintpl3/commit/84a9fcd37f7dc48ea86892e90fd2cf9682759f8d

Let us know if this fix your problem.
Thanks!

Michael Keplinger

unread,
May 24, 2012, 10:57:01 PM5/24/12
to raintpl
AWESOME. Thanks so much

Federico Ulfo

unread,
May 24, 2012, 10:59:10 PM5/24/12
to rai...@googlegroups.com
Thanks so much for your help, very appreciated.

On Thu, May 24, 2012 at 10:57 PM, Michael Keplinger <mi...@athleticxtreme.com> wrote:
AWESOME.  Thanks so much

Michael

unread,
May 29, 2012, 1:38:00 AM5/29/12
to raintpl
Hi Guys,

Sorry to keep bothering about this issue, but I still just don't
understand how Rain is supposed to work with different templates.
Do ALL templates need to be stored in the tpl_dir directory? or can
some templates files be stored in subdirectories?

for example // ( I would expect that in product1.php, I can call tpl-
>draw('product1') OR tpl->draw('products/product1')

webroot
| ---> index.php
| ---> about-us.php
| ---> [] products
| ---> index.php
| ---> product1.php

| ---> [] templates
| ---> home.html
| ---> about-us.html
| ---> [] products
| ---> product1.html



can you please verify that all templates must be stored directly in
tpl_dir ??? an cannot use any subdirectories. IF you can use
subdirectories, could you please explain better.

thanks.
Michael

Rain Team

unread,
May 29, 2012, 11:23:57 AM5/29/12
to rai...@googlegroups.com
Hi Michael, 
yes you can use subfolder, this is the best way to organize your projects! Can you print here your error and the code that use RainTPL3 beta?
The code it should look something like this:

use Rain\Tpl;

Tpl::configure("tpl_dir", "templates");
$t = new Tpl;
$product_html = $t->draw( "products/product1", $to_string = true ); // render template product1 and return a string

$t = new Tpl;
$t->assign( "product_html", $product_html );
$t->draw( "home" ); // draw the template home

Time allowing we'll add soon the user guide for RainTPL 3.
Thanks


Michael Keplinger

unread,
May 29, 2012, 12:01:30 PM5/29/12
to raintpl
I keep trying this all different ways and cannot get it to work

Here is the error code that you asked for,


Fatal error: Uncaught exception 'Rain\RainTpl_NotFoundException' with
message 'Template product1 not found!' in /home/developm/public_html/
code/vendors/Rain/Tpl.php:190 Stack trace: #0 /home/developm/
public_html/code/vendors/Rain/Tpl.php(78): Rain\Tpl-
>_check_template('studies/product...') #1 /home/developm/public_html/
studies/product_study/index.php(37): Rain\Tpl->draw('studies/
product...', true) #2 {main} thrown in /home/developm/public_html/code/
vendors/Rain/Tpl.php on line 190

===============
my page is loaded with the following. (Note that. my page template
has quite a few {include="pages"} for files that are in my template
directory for the header, footer, and javascript files that are used
side wide)

This php file exists here:
webroot
| ---> [] studies
| ---> [] product1
| ---> index.php


<?php

// namespace
use Rain\Tpl;

// include
include "../../code/vendors/Rain/Tpl.php";

// Temporary during development
$base_url = "http://".$_SERVER['SERVER_NAME'] . "/";

// config
$config = array(
"base_url" => $base_url,
"tpl_dir" => "templates/ax/",
"cache_dir" => "cache/",
"debug" => true,
"auto_escape" => false,
);

Tpl::configure( $config );

// Add PathReplace plugin
require_once('../../code/vendors/Rain/Tpl/Plugin/PathReplace.php');
Rain\Tpl::register_plugin( new Rain\Tpl\Plugin\PathReplace());


//initialize a Rain TPL object

$t = new Tpl;
$t->draw( "studies/product1" ); //

=========================================

Then in the template directory (templates/ax), I have the following
(where the html file is a plain HTML file with a few includes to other
templates that contain the header and footer., such as
{include="static-content/stylesheets"} )
webroot
| ---> [] templates
| ---> [] studies
| ---> product1.html

=======
I get the above error when loading. I have tried it also with sending
the output to a string and then loading a different template, but
RainTpl just cannot find the template.

Federico Ulfo

unread,
May 29, 2012, 12:15:47 PM5/29/12
to rai...@googlegroups.com
I think I figure out the problem, you're including Rain from webroot/studies/prodcut1/index.php with
include "../../code/vendors/Rain/Tpl.php";

instead of a relative path try to include Rain with the absolute path, I'm sure that will fix the problem. In any cases we'll take a look at it, to make it works also with relative paths.

Keep us updated, we'll post here any news regarding this fix.

Reply all
Reply to author
Forward
0 new messages