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

Smarty start

 
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 -> General
View previous topic :: View next topic  
Author Message
yamokosk
Smarty n00b


Joined: 29 May 2003
Posts: 2

PostPosted: Thu May 29, 2003 4:02 am    Post subject: Smarty start Reply with quote

I am new to Smarty but seasoned with PHP. Like every other developer with out a template system I have always embedded my PHP/app code in HTML, so that may be why I am having a tough time grasping Smarty.

Here are my questions/comments:

Many smarty resources that I have read say that Smarty template files should be located in a non-Web readable folder. For example:

/usr/local/apache/htdocs --> root web folder
/usr/local/templates --> location of template files

But if you logically store the image files in a sub-folder of the template file directory (e.g. /usr/local/templates/images), don't you run into a mess with relative links? Are the images even readable by a Apache server? I tried this setup and no matter wether I used absolute or relative paths the images would not appear when the page was displayed. Now when I moved the templates folder (and the associated images sub-folder) beneath the web root, I had no problem displaying images.

I read a previous post on this forum where someone suggested using pre-filters to avoid messes with relative image links. Is that the only way to deal with images and templates? Furthermore, do template files and images have to be located in a web-readable directory?

Basically, is there something I am mis-understanding when it comes to a sites directory structure and Smarty implementation?
Back to top
View user's profile Send private message
boots
Administrator


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

PostPosted: Thu May 29, 2003 5:53 am    Post subject: Reply with quote

hi yamokosk--

Thanks for posting. I think you are right that many people who start using template systems stumble a little bit on the distinction between url paths and filesystem paths.

Clients don't actually call templates -- they call php webpages (via an url) that process templates. Basically, the url of the requested php webpage determines the context of the relative urls in your HTML code.

This is nothing new, of course, but the difference is in your logical design. When designing templates, things that require urls (like your HTML images) need to specify url paths relative not to the template's physical directory hierarchy but instead to the url of the page that they are ultimately called from. This has been discussed to some extent on this forum, mainly in regards to using visual tools like Dreamweaver. Note that since templates can be loaded from resources, they do not necessarily exist in the filesystem at all.

For example, if you are using a flat structure for you web pages (all web pages are from the same directory, say //mysite/) and the images directory is located at //mysite/images then ALL templates that refer to images/* will always point to the url //mysite/images/* since the templates are called from a file originating at the url //mysite/.

I usually run around this altogether by either assigning the path to the image directory in a template variable or declaring it in a config file which the template loads and then prefixing paths with that in the template.

As always, your images need to be in a client accessable url path. It is strongly suggested that your templates are not accessable from an url path, especially since they don't need to be.

HTH
Back to top
View user's profile Send private message
sweatje
Smarty Regular


Joined: 17 Apr 2003
Posts: 70
Location: Bettendorf, Iowa, USA

PostPosted: Thu May 29, 2003 1:26 pm    Post subject: Reply with quote

a simple
Code:
 $echo DENY from ALL > .htaccess
in the templates directory should take care of you in apache, even if the templates directory is in the document root.
_________________
Jason
jsweat_php AT yahoo DOT com
Back to top
View user's profile Send private message
yamokosk
Smarty n00b


Joined: 29 May 2003
Posts: 2

PostPosted: Fri May 30, 2003 3:11 am    Post subject: thanks Reply with quote

Boots: thanks for the info. I have some experience with the point you were trying to make. I once wrote an XML parser.. the XML docs referenced images in html, but the parser (php file) wasn't in the same directory as the xml files.

I guess what I was trying to get at was a point you mentioned briefly, about making template files compatible with both the calling php file for the browser AND for a graphical editor like DW. To that end I implemented a simple pre-filter that was mentioned on some other post.

yamokosk
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 -> General 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