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

Include doesn't work...

 
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 -> Help Wanted (commercial)
View previous topic :: View next topic  
Author Message
leonarth
Smarty n00b


Joined: 24 May 2010
Posts: 4

PostPosted: Mon May 24, 2010 3:06 pm    Post subject: Include doesn't work... Reply with quote

Code:
{if $loggedin}

{literal}
{include file="allhead.html"}
{/literal}

{else}

{literal}
{include file="allhead1.html"}
{/literal}

{/if}


How do I include the code contained into an HTML file in a smarty .tpl file? I've tried different solutions on various forums, but none work.
Back to top
View user's profile Send private message
douglassdavis
Smarty Junkie


Joined: 21 Jan 2008
Posts: 541

PostPosted: Mon May 24, 2010 3:32 pm    Post subject: Re: Include doesn't work... Reply with quote

leonarth wrote:
Code:
{if $loggedin}

{literal}
{include file="allhead.html"}
{/literal}

{else}

{literal}
{include file="allhead1.html"}
{/literal}

{/if}


How do I include the code contained into an HTML file in a smarty .tpl file? I've tried different solutions on various forums, but none work.


remove the {literal} tags
Back to top
View user's profile Send private message
leonarth
Smarty n00b


Joined: 24 May 2010
Posts: 4

PostPosted: Mon May 24, 2010 5:49 pm    Post subject: Reply with quote

Still doesn't work. Any other idea?
Back to top
View user's profile Send private message
douglassdavis
Smarty Junkie


Joined: 21 Jan 2008
Posts: 541

PostPosted: Mon May 24, 2010 5:51 pm    Post subject: Reply with quote

leonarth wrote:
Still doesn't work. Any other idea?


Is the HTML file in the same dir as your templates? If not you may need to use a relative path to the HTML file.

I'm not sure if there is any restriction on including html files. I'm not aware of one, so I think it should work.
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Mon May 24, 2010 6:34 pm    Post subject: Reply with quote

Code:
{if $loggedin}

{fetch file="allhead.html"}

{else}

{fetch file="allhead1.html"}

{/if}


The {fetch} function fetches static (non-smarty) files. Path is relative to the executing PHP script.

http://www.smarty.net/fetch
Back to top
View user's profile Send private message Visit poster's website
leonarth
Smarty n00b


Joined: 24 May 2010
Posts: 4

PostPosted: Mon May 24, 2010 6:41 pm    Post subject: Reply with quote

I've tried also the fetch function, still doesn't work. The html file contain this html code:

Code:
<div id="navigation">

<UL class="nav">
<li><a href="http://ifaoro.com/">Home</a></li>
<li><a href="http://ifaoro.com/hosting/">Web Hosting</a></li>
<li><a href="http://ifaoro.com/services/">Services</a></li>
<li><a href="http://ifaoro.com/software/">Software</a></li>
<li><a href="http://ifaoro.com/signup/">Signup</a></li>
   
</div>


For some reason I can't get this code included by the include function in my .tpl files.
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Mon May 24, 2010 6:49 pm    Post subject: Reply with quote

where is the HTML file located? And where is the PHP file being executed? You have to get the file path right.
Back to top
View user's profile Send private message Visit poster's website
leonarth
Smarty n00b


Joined: 24 May 2010
Posts: 4

PostPosted: Mon May 24, 2010 7:25 pm    Post subject: Reply with quote

mohrt wrote:
where is the HTML file located? And where is the PHP file being executed? You have to get the file path right.


It's not a php but an html file.
It is in the same directory as the .tpl file. I've tried both filename and full \path\to\filename.

Are you sure I can include that HTML code I've posted earlier using the fetch function? Does it work for you?
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Mon May 24, 2010 7:50 pm    Post subject: Reply with quote

if it is in the template directory, you can use {include ...} but it will get (needlessly) compiled as a template file.

If it is just an .html file, you should probably not keep in in the template_dir, instead put it in the document root or other directory, then grab it with {fetch}

You have to have the path right for a {fetch}. For instance if your URL says /index.php, then the path must be relative to that file location. You could also use an absolute system file path

{fetch file="/system/file/path/to/foo.html"}
Back to top
View user's profile Send private message Visit poster's website
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 -> Help Wanted (commercial) 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