feulf / raintpl3

The easiest Template Engine for PHP
https://feulf.github.io/raintpl
258 stars 57 forks source link

Absolute path #128

Closed feulf closed 10 years ago

feulf commented 10 years ago

implemented absolute path for {include} tag

feulf commented 10 years ago

Please review

prisis commented 10 years ago

i tested your code an get 2 errors

file_exists(): open_basedir restriction in effect. File(/www/htdocs/w00/c.de/c_dev/c_v3/Frontend/Themes/admin/desktop/CACP/index.html/) is not within the allowed path(s): (/www/htdocs/w00/:/tmp:/usr/bin:/www/htdocs/w00:/bin:/usr/local/bin:/usr/share/php)

and if i chance 
$templateBasedir = strpos($template, DIRECTORY_SEPARATOR) !== false ? dirname($template) . DIRECTORY_SEPARATOR : null;
to
$templateBasedir = $template !== false ? dirname($template): null;

fopen(/www/htdocs/w00f2e51/c.de/c_dev/c_v3/Frontend/Modul/admin/desktop/CACPindex.html/): failed to open stream: No such file or directory

and my settings are

realpath(dirname(__FILE__)).DS,true) .  $publicfolder . DS .  'Modul or Themes'

if you like i can give you a test acc, than you can see the errors your self

feulf commented 10 years ago

There was an error in the addTrailingSlash method, can you please check again? Thanks

prisis commented 10 years ago

now it works. but i have still a littel problem, how i can set two random folder?

admin/desktop/C/ is my main Themes folder and Content/Tpl/ is my module folder

but i get something like that...

<?php require $this->checkTemplate("admin/desktop/C/Content/Tpl/content");?> <?php require $this->checkTemplate("admin/desktop/C/footer");?>

feulf commented 10 years ago

Can you show me your template and explain with different words?

Thanks

prisis commented 10 years ago

so i will try to explain what i mean. first: her is a screen shot of my folders http://s14.directupload.net/images/131127/wxvwbp2y.jpg

on the right side you can see my index tpl-

Now, i have a folder where i have all my Templates (themes folder) and a Module folder where all my modules are. All my modules have a Tpl folder there are all tpls for my modules are and i like to load that Tpls in my Themes folder white include tag

like {include="Content/Tpl/content"}

feulf commented 10 years ago

I understood your problem.

This solution should solve your problem:

{include="{#MODULES_DIR#}/Content/tpl/content"}

Another solution is to add in the "tpl_dir" both the theme folder and the modules folder, so whenever Rain can't find a template in the theme folder it will search it in the modules folder.

prisis commented 10 years ago

If i test your first example, i get only the full path of my file and no include.

{include="{#MODULES_DIR#}/Content/tpl/content"}

/www/htdocs/w/c/c/c/Frontend/Modul/Content/Tpl/content"} at the end, is a } too little.

I have both folder in my tpl_dir settings, but it looks always after admin/desktop/C/Content/Tpl/content, but it should by like admin/desktop/C/footer and Contetn/Tpl/content

if ($_ENV['SLIM_MODE'] === 'development') {
            // reconfiguring RainTPL
            $config = array(
                "base_url"  => SCRIPTPATH,
                "include_path" => array(
                ),
                "tpl_dir"  => array(
                    self::$TemplateDir . DS,
                    self::$ModulTemplateDir,
                ),
                "cache_dir" => self::$CacheTemplateDir,
                "tpl_ext" => \ConfigLoader::item('tpl_suffix', 'ConfigConfig'),
                "path_replace" => false,
                "auto_escape" => true,
                'allow_compile_once' => false,
                "debug"     => true, // set to false to improve the speed
            );

        } else {
            // reconfiguring RainTPL
            $config = array(
                "base_url"  => SCRIPTPATH,
                "include_path" => array(
                ),
                "tpl_dir"  => array(
                    self::$TemplateDir . DS,
                    self::$ModulTemplateDir,
                ),
                "cache_dir" => self::$CacheTemplateDir,
                'tpl_ext' => \ConfigLoader::item('tpl_suffix', 'ConfigConfig'),
                "path_replace" => false,
                "auto_escape" => false,
                "debug"     => false, // set to false to improve the speed
            );
        }

TPL in Themes/admin/desktop/C/index:

{include="Content/Tpl/content"}
{include="footer"}

TPL output:

<?php require $this->checkTemplate("admin/desktop/C/Content/Tpl/content");?> 
<?php require $this->checkTemplate("admin/desktop/C/footer");?>
feulf commented 10 years ago

What about this solution?

{$module_dir="module_dir/"}
{$include_file="$module_dir/your_template"}

In case this doesn't work you'll have to use absolute path, and eventually we'll work on a better solution for include path.

Please let me know.

prisis commented 10 years ago

thats how i do it right now, but i dont like that solution that much, will look in to smarty how they handle the include tag and make a plugin or some modification on the tpl.php

feulf commented 10 years ago

I'll merge this for now. @prisis please open a new ticket for your problem and we'll work on it, thanks.