For Programmers: Free Programming Magazines  


Home > Archive > PHP Smarty Templates > July 2004 > RE: [SMARTY] Javascript Question









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author RE: [SMARTY] Javascript Question
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
Vonleigh Simmons

2004-07-01, 8:59 pm

> Good point, and I actually figured it out:

Your page is broken though, because screen_res.php gets output before
your header.


Vonleigh Simmons
<http://illusionart.com/>

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com