raintpl3
raintpl3 copied to clipboard
Error on Windows Machine with Template Subfolders
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.
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 /
How can I use this constant? Can you give an example?
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...
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:
@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.
Can you please review my change and check on a Windows machine.
Looks like a very simple solution :D
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.
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 [email protected] 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.
DIRECTORY_SEPARATOR is a global php constand depending on your operating system. It is always defined because it's a php default constant.
Added workaround #162