View previous topic :: View next topic |
Author |
Message |
webvivekar Smarty Rookie
Joined: 21 Oct 2003 Posts: 8
|
Posted: Fri Sep 24, 2004 5:55 pm Post subject: fetch file - variables not assigned |
|
|
Hi,
I am surprised to find that while `fetch`-ing a file, it does not assign the values to the variables
already assigned.
In the previous version "Smarty-2.6.0-RC2", this worked perfectly.
---------------------------------------------------------
file: example.tpl
Hi {$username},
welcome to the smart world
Fullname: {$user_fullname}
Email : {$email}
---------------------------------------------------------
test.php
$tpl->assign("username", $this_username);
$tpl->assign("user_fullname", $this_userfullname);
$tpl->assign("email", $this_useremail);
$content = $tpl->fetch("example.tpl");
echo $content;
-----------------------------------------------------------
The above example worked with "Smarty-2.6.0-RC2"
It is not working in "Smarty 2.6.5"
Am i doing something wrong? |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Fri Sep 24, 2004 6:03 pm Post subject: |
|
|
uh, why do you say it doesn't work? Your example HAS to work--I mean, that's what Smarty does. If it didn't work, there wouldn't have been a release. FWIW, I use fetch all the time and I'm not seeing the same issue you suggest. |
|
Back to top |
|
webvivekar Smarty Rookie
Joined: 21 Oct 2003 Posts: 8
|
Posted: Wed Sep 29, 2004 5:43 am Post subject: |
|
|
Hi,
I tested it a few times. It still did not work.
Here are the full details.
---------------------------------------------------------
// example.tpl
---------------------------------------------------------
<pre>
Hi {$myusername},
Fullname: {$myuser_fullname}
Email : {$myemail}
</pre>
#----------------------EOF-------------------------------
---------------------------------------------------------
// blurb.tpl
---------------------------------------------------------
This is the blurb.
{$blurb}
It is found at {$siteurl}
#----------------------EOF-------------------------------
---------------------------------------------------------
// smartytest.php
---------------------------------------------------------
<?php
$DIR_UP = "../";
$sitedebug = 1;
error_reporting (E_ERROR | E_PARSE);
require_once $DIR_UP . '/class/smarty_new/libs/Smarty.class.php'; //version: 2.6.5-dev
//require_once $DIR_UP . '/class/smarty/libs/Smarty.class.php'; //version: 2.6.0
//$mytheme = "bliss";
$tpl = new Smarty;
$tpl->template_dir = $DIR_UP. "themes";
$tpl->cache_dir = $DIR_UP. "cache";
$tpl->debugging = $sitedebug;
$tpl->compile_dir = $DIR_UP . "templates_c";
//-------------
$this_username = "abraham";
$this_userfullname = "Abraham Lincoln";
$this_useremail = "abraham.lincoln AT whitehouse DOT gov";
$tpl->assign("myusername", $this_username);
$tpl->assign("myuser_fullname", $this_userfullname);
$tpl->assign("myemail", $this_useremail);
$content = $tpl->fetch("example.tpl");
//TODO: consecutive fetch. to be tested
//-------------
$blurb = "What is you see is what you get";
$siteurl = "http://smarty.php.net";
$tpl->assign("snippet", $blurb);
$tpl->assign("website", $siteurl);
//concat with old content
//$content .= $tpl->fetch("blurb.tpl");
//echo "content is " . $content;
$tpl->assign("page_content", $content);
$tpl->display( "templatepage.tpl");
?>
---------------------------------EOF---------------------
---------------------------------------------------------
//file: templatepage.tpl
---------------------------------------------------------
<html>
<title>{$page_heading|default:"untitled"}</title>
<body>
{$page_content}
<hr>
{$page_footer}
</body>
</html>
---------------------------------EOF---------------------
---------------------------------------------------------
Here is the debug console output
---------------------------------------------------------
Smarty Debug Console
included templates & config files (load time in seconds):
example.tpl
templatepage.tpl (0.00519)
assigned template variables:
{$SCRIPT_NAME} /test/smartytest.php
{$myemail} abraham.lincoln AT whitehouse DOT gov
{$myuser_fullname} Abraham Lincoln
{$myusername} abraham
{$page_content} empty
{$snippet} What is you see is what you get
{$website} http://smarty.php.net
assigned config file variables (outer template scope):
{#files#} Array (0)
{#vars#} Array (0)
----------------------------------------------------------
see the {$page_content} is "empty" |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Wed Sep 29, 2004 2:26 pm Post subject: |
|
|
Hmm. I looked at your example and it looks ok... I'm not sure what you have in your example.tpl, though and I'd suggest that while debugging, you keep error reporting at E_ALL. I'm also wondering if you cleared your templates_c and cached folders since you upgraded.
I depend on this functionality, so I know it should work. I even tried using a simplified version of your example:
[php:1:cab5a05abc]<?php
$content = $tpl->fetch("content.tpl");
die($content);
?>[/php:1:cab5a05abc]
Where content.tpl contains the text "content.tpl" and $tpl is a properly configured subclass of Smarty. The result is "content.tpl" as expected.
It also just occured to me: where in your path does example.tpl exist? Smarty no longer searches your php include path for templates. Does that affect you? |
|
Back to top |
|
webvivekar Smarty Rookie
Joined: 21 Oct 2003 Posts: 8
|
Posted: Fri Oct 01, 2004 12:04 am Post subject: |
|
|
All the files are in same folder.
No, I did not clear any files in templates_c or cache.
Even, If I cleared it, it should have regenerated.
Shouldn't it? |
|
Back to top |
|
webvivekar Smarty Rookie
Joined: 21 Oct 2003 Posts: 8
|
Posted: Fri Oct 01, 2004 12:14 am Post subject: |
|
|
While Error reporting E_ALL,
I am getting this error
Code: |
Smarty error: unable to read resource: "example.tpl"
|
Since all the files are in the same folder, why it could not find it? |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Fri Oct 01, 2004 2:48 am Post subject: |
|
|
Ahh. That seems to make more sense. Now, why is it finding the one template and not the other is a good question.
Troubleshooting Tips: try each of these in order and test after each.
- Clear out the compiled and cached directories to make sure (or set $smarty->force_compile = true).
- Make sure that there are no copies of templatepage.tpl in other locations, again to ensure that Smarty is retrieving your templates from the expected spots.
- Ensure that $smarty->template_dir is pointing to the correct path just prior to calling fetch().
- Make sure that you can access your template files using file_get_contents($DIR_UP. "themes/".$template_name).
-Make sure the user access permissions for the template files match what your webserver is capable of. |
|
Back to top |
|
|