why not?
just divide your every application into 2 parts - data preparation and data displaying.
Say, your data preparation part (also called "business logic") may look like
<?
include 'config.php';
$data=db_query("SELECT * FROM data",3);
display($data,"users_list.tpl");
?>
Note the display() function. It's the function responsible for the data output. It can render both HTML and JSON, depends on the destination.
It code may look like
<?
if ($destination == 'desktop') echo json_encode($data);
else include $template;
?>
and users_list.tpl may look like
<a href="?id=0">Add item</a>
<? foreach ($data as $row): ?>
<li><a href="?id=<?=$row['id']?>"><?=$row['name']?></a>
<? endforeach ?>
Very simple. Just avoid echo $row['name']; things in your business logic code.