| Scott Phelps 2004-07-01, 4:02 pm |
| On Wed, 2004-06-30 at 17:05, Hoffman, Geoffrey wrote:
> Really challenging for PHP in general, but even more so for Smarty, due to
> the following:
> - Smarty doesn't have access to your client-side .js
> - PHP doesn't have direct access to screen.x or screen.y
>
> By design, you want to avoid placing PHP code in your .tpl files wherever
> possible.
>
Good point, and I actually figured it out:
--------------------------------------------------------
In my index.php file, I just add:
--------------------------------------------------------
<?
require('includes/screen_res.php');
$smarty->assign('screen_res',$screen_res);
$smarty->display('index.tpl');
?>
-------------------------------------------------------
and in my screen_res.php:
-------------------------------------------------------
<?php
if (isset ( $HTTP_COOKIE_VARS['screen_res'] ))
$screen_res=$HTTP_COOKIE_VARS['screen_re
s'];
else {
?>
<script language="javascript">
write_screen_res_cookie();
</script>
<?php
}
$screen_res = $HTTP_COOKIE_VARS['screen_res'];
?>
-------------------------------------------------------
and in my index.tpl:
-------------------------------------------------------
{* Smarty *}
{include file="header.tpl"}
Your screen resolution is: {$screen_res}
{include file="footer.tpl"}
-------------- end -------------------
BTW, Your way should work, but I like this better since it keeps me from
having to use literal tags - which I think is cleaner.
--
Thank you,
Scott Phelps
|