Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

unable to read resource.

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Installation and Setup
View previous topic :: View next topic  
Author Message
mythology
Smarty Rookie


Joined: 06 Sep 2004
Posts: 12

PostPosted: Wed Sep 22, 2004 5:49 am    Post subject: unable to read resource. Reply with quote

Quote:
Warning: Smarty error: unable to read resource: "intro.tpl" in /home/dustinh/public_html/libs/Smarty.class.php on line 1083


I just installed, well tried, the Smarty engine. My site has an... I guess, unusual organization:

./libs/
./site/
./index.php (intro)
./site/index.php (site homepage)
./templates/
./templates/cedar_red/intro.tpl

So, I have all my libs and stuff like that in my root, then I have my templates and stuff inside of my /site/ folder. Don't ask why it's set up like this, it's just something that helps me keep the enormous amount of content organized. Anyway, I'm trying to use the Smarty engine on the intro page (index.php) which is located in the root directory. I can't get it to locate the template which is placed in ./site/templates/cedar_red/intro.tpl.

I'm not sure if you guys have ever had anything like this pop up or not, but I could sure use some help. Thanks!
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Wed Sep 22, 2004 1:49 pm    Post subject: Reply with quote

This is usually a problem with relative paths to the smarty directories. Smarty will try to find the directories relative to the executed script. It is usually less error-prone to provide absolute paths to them:

$smarty->template_dir = '/path/to/templates';
$smarty->compile_dir = '/path/to/templates_c';
$smarty->cache_dir = '/path/to/cache';
$smarty->config_dir = '/path/to/configs';

Or for a bit more flexible install, setup a constant, something like:

define('MY_PATH', dirname(__FILE__));

$smarty->template_dir = MY_PATH . '/templates';
$smarty->compile_dir = MY_PATH . '/templates_c';
$smarty->cache_dir = MY_PATH . '/cache';
$smarty->config_dir = MY_PATH . '/configs';

If you're running windows, path name syntax adjustments do apply, of course.
Back to top
View user's profile Send private message Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Wed Sep 22, 2004 1:55 pm    Post subject: Reply with quote

Where is your template directory again? You mentioned ./site/templates/cedar_red/intro.tpl, although your directory layout suggests ./templates/cedar_red/intro.tpl. Make sure your template_dir path is correct, then you execute:

$smarty->display('cedar_red/intro.tpl');
Back to top
View user's profile Send private message Visit poster's website
mythology
Smarty Rookie


Joined: 06 Sep 2004
Posts: 12

PostPosted: Thu Sep 23, 2004 8:00 pm    Post subject: Reply with quote

Awesome, that got it. Thanks!

The only problem I'm having now is it won't pull the information from my datbase:

Code:

$sql = "SELECT config_value FROM website_config WHERE config_name = 'website_title'";
$site_title = mysql_query($sql);

$template -> assign('site.title', $site_title);


It's being called with {$site.title}, but it's just coming up blank. I've checked my connection to the database, and it works, but it just doesn't want to put the info there. Is there anything that I'm missing? Oh, btw, I am using $template = new Smarty; just incase. Smile

Edit:
I've also used $template -> assign('site.title', 'test'); and gotten nothing.
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Thu Sep 23, 2004 8:20 pm    Post subject: Reply with quote

{$site.title} == array('site'=>array('title'=>value));

Thus:

$site['title'] = $site_title;
$template -> assign('site', $site);
Back to top
View user's profile Send private message
mythology
Smarty Rookie


Joined: 06 Sep 2004
Posts: 12

PostPosted: Thu Sep 23, 2004 8:33 pm    Post subject: Reply with quote

lol, boots, you lost me.

I wanted to see if it would work without any interaction from the DB or anything so I tried this:

Code:

// Calling it in the tpl as {$title}
$template -> assign('title', 'test');


and still having no luck. I'm reading over the crash course docs, and I've done it all correctly (I think)... but it's still just blank.
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Thu Sep 23, 2004 10:31 pm    Post subject: Reply with quote

Hey-o, don't mind me, its actually very simple. When you say {$foo.bar} in a template, you are saying "from the array $foo, return the item with key 'bar'". That's inside a template. In your PHP code (including the functions and methods that are part of Smarty) you need to use regular array syntax. So to set the template var $foo.bar, you have to assign to Smarty something like:

$smarty->assign('foo', array('bar'=>'xyz'));

This assigns the $foo template variable as an array with an element whose key is 'bar'. My earlier example was meant to demonstrate essentially the same thing but I guess I had --terse-mode=9 Smile.

Cheers!
Back to top
View user's profile Send private message
mythology
Smarty Rookie


Joined: 06 Sep 2004
Posts: 12

PostPosted: Thu Sep 23, 2004 11:45 pm    Post subject: Reply with quote

lol, it was starting to piss me off that it wouldn't work, but then i realized it was the cache that wasn't changing it for one reason or another in my browser. Thanks for the replies.

Anyway, now that I've got it where it will grab the information... it's doing something weird now:

Code:

// Table definition
define('WEBSITE_CONFIG', 'website_config');

// Pull the site title from SQL
$sql = "SELECT `config_value` FROM `" . WEBSITE_CONFIG . "` WHERE 1 AND `config_name` = 'website_title'";
$site_title = mysql_query($sql);

// Display it
$template -> assign('siteTitle', $site_title);


The result: Resource id #7

Is this something in Smarty's or am I just screwing up on the SQL code?
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Thu Sep 23, 2004 11:52 pm    Post subject: Reply with quote

That's because mysql_query() returns a resource handle, not a result-set.

Better take another look at http://php.net/manual/en/ref.mysql.php Smile
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Installation and Setup All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP