RE: [SMARTY] Javascript Question
| From: | Scott Phelps | Date: | Thu, 01 Jul 2004 13:04:14 +0000 |
| Subject: | RE: [SMARTY] Javascript Question | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-11514@lists.php.net to get a copy of this message | ||
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_res'];
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