MyBB Community Forums

Full Version: Help with a template system i am writing.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am going with file templates.

global.tpl contains this for testing
<html>
<body>
<head>
<title>test template</title>
</head>
{$contents}
</body>
</html>

As you can see, every tag is on a new line, however when the template is echoed, this is what i get when i view the source:

<html><body><head><title>test template</title></head>conteent</body></html> 

I have no idea why it is like that. The file is saved as UTF-8 Without the Byte Order Mark with Notepad++. I should get what i have written, but it's displayed on one line

How do i get and echo the template? Very simple:

function echo_templates($template_name, $content)
{
    $template = file_get_contents(ROOT."include/templates/global.tpl");
	
	$echo_template = preg_replace("/".preg_quote('{$contents}')."/", $content, $template);
	
	echo $echo_template";
}

I found the problem. It is Notepad++ at fault here, though i don't know why. As soon as i opened it with regular Notepad, i saw that everything was on one line and so fixed it.

But why though? When i opened the edited file with Notepad++, everything was like

<html>

<body>

<head>

<title>test template</title>

</head>

{$contents}

</body>

</html>
Line ending conventions, probably. Linux/Mac OX X simply use \n, whereas Windows and the HTML spec use \r\n (Mac OS 9 and lower use just \r).

Programmer's Notepad 2 allows you to switch line ending style (useful for open source projects), but IIRC is a Windows-only program...