feulf / raintpl3

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

Error on Windows Machine with Template Subfolders #121

Open Reflic opened 10 years ago

Reflic commented 10 years ago

Hello guys,

i am developing a project with some friends. Im the only one who works on a Linux (Ubuntu 13.04) Machine. My friends all work on their Windows PCs.

But now i have encounterd a problem.

I have organized my templates in subfolders so my folderstructure looks like this.

views ├── home.html ├── layout │   ├── footer.html │   └── header.html ├── login.html └── register.html

The template home now includes both footer and header with the following command. {include="layout/header"}

This works great on my linux machine.

But in the Windows machine of my friend. The template is not found.

Printing the complete filepath of the template which is searched for. Gives me this path: views/header.html and not as it should be views/layout/header.html.

I have found out that when replacing the char / with \ it works like a charm on windows but not on my linux machine.

Am I doing something wrong? Or is this a real bug? I will provide more information of course just ask for it.

biggingernerd commented 10 years ago

You should try out DIRECTORY_SEPERATOR constant instead of using /, this contains the seperator based on the OS you're on. So on Windows this would be \ instead of /

Reflic commented 10 years ago

How can I use this constant? Can you give an example?

mvmaasakkers commented 10 years ago

This is a predefined constant in PHP. So, in PHP it's as simple as: $template = "layout".DIRECTORY_SEPERATOR."header";

Not sure what the best way is to do this in raintpl, but you could pass $template as a variable and use it like that...

keskad commented 10 years ago

Anyway Unix directory separators should also work on Windows as it also accepts relaitve paths like aaa/bbb/ccc or c:/test/123.

So, I think this is not a problem. And, how anybody can develop PHP code on Windows... :smile:

Reflic commented 10 years ago

@webnull Maybe it should but they dont. :) btw: I dont know how, but they are real beginners so it will work sometime.

@mvmaasakkers Mmh ok, thats a kinda dirty solution in my mind but ok thx.

feulf commented 10 years ago

Can you please review my change and check on a Windows machine.

keskad commented 10 years ago

Looks like a very simple solution :D

wu3rstle commented 9 years ago

Could you please replace DIRECTORY_SEPARATOR with '/'?

Problem on windows machine is that there will be some misbehavior:

'template'.DIRECTORY_SEPARATOR.'test'

will be included as

'template{TAB}est'

same for every character that needs to be used as escapestring.

Also your examples will be runnable on a windows machine.

feulf commented 9 years ago

that's awkward, for now you can add:

if (!defined("DIRECTORY_SEPARATOR") {
    define("DIRECTORY_SEPARATOR", "/" );
}

I think we should add that inside the Tpl.php file.

On Fri, Nov 14, 2014 at 11:45 AM, Tobias Negd notifications@github.com wrote:

Could you please replace DIRECTORY_SEPARATOR with '/'?

Problem on windows machine is that there will be some misbehavior:

'template'.DIRECTORY_SEPARATOR.'test'

will be included as

'template{TAB}est'

same for every character that needs to be used as escapestring

— Reply to this email directly or view it on GitHub https://github.com/rainphp/raintpl3/issues/121#issuecomment-63092808.

wu3rstle commented 9 years ago

DIRECTORY_SEPARATOR is a global php constand depending on your operating system. It is always defined because it's a php default constant.

wu3rstle commented 9 years ago

Added workaround #162