• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Simple template system

zakius

Enter the Ninja!
Joined
Apr 30, 2009
Messages
2,635
Reaction score
65
Location
with Taiga
Hello, I would like to use some template system in my web project. But I don't feel like using smarty and the way gesior made it doesn't look too good also. After googling a bit I found mtemplate. But still I'd like o know if you know any better way?(something fast, not too hard to implement and easy to create templates for it)
 
I dont understand why people want to use template system if php is good template system, u have short tags, loops, conditions, and php is faster than any template system.
 
I know this and for myself I use just php mixed with html. But for project where to change template you have to upload it and change config that won't work. So I can use gesiors method or mtemplate probably. Smarty is too big and complex so it probably would cause too big slowdowns.
 
I know this and for myself I use just php mixed with html. But for project where to change template you have to upload it and change config that won't work. So I can use gesiors method or mtemplate probably. Smarty is too big and complex so it probably would cause too big slowdowns.
Why? why can't you solve this with just php?
 
Actually template system IS php. And I'm asking what is the best way to get exact output from the layout script and combine it with other parts properly. I just need the idea, if I'm not able to code it after having solution explained then I should learn more and then continue this project
 
Parsing. Ex:

index.php
PHP:
function parse($file, $args = array())
{
	ob_start();

	// Extract argument's array and include file
	extract($args);
	include $file;

	$f = ob_get_contents();
	ob_end_clean();

	return $f;
}

$array = array(array(
				'title' => 'Lorem Ipsum',
				'text'  => '<p>ulla facilisi. Nulla orci ligula, varius eget tincidunt facilisis, consectetur eget sem.</p>'
			),array(
				'title' => 'Nulla facilisi',
				'text'  => '<p>Etiam consectetur, libero sit amet suscipit tempus, lectus nisl commodo nibh, et ornare eros lorem eget lectus. .</p>'
			));

$vars = array();

$vars['content'] = parse('article.php', array('articles' => $array));
$vars['title']   = 'Website title';

echo parse('layout.php', $vars);

article.php
PHP:
<?php foreach($articles as $a){ ?>
		<h1><?php echo $a['title'];?></h1>
		<h1><?php echo $a['text'];?></h1>
		<hr/>
<?php } ?>

layout.php
PHP:
<!DOCTYPE html>
<html>
<head>
	<title><?php echo $title;?>
</head>

<body>
	<?php echo $content;?>
</body>
</html>
 
Well, that even looks quite right.
But this way it would be better to use MVC probably(to first get values from db and then pass them to "content" code and then pass content to layout)
But nothing will break if I'll just make it "normal" way, just parse for content would contain only config array
Yeah, looks really nice
Big thanks
 
Back
Top