View previous topic :: View next topic |
Author |
Message |
leonarth Smarty n00b
Joined: 24 May 2010 Posts: 4
|
Posted: Mon May 24, 2010 3:06 pm Post subject: Include doesn't work... |
|
|
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 |
|
douglassdavis Smarty Junkie
Joined: 21 Jan 2008 Posts: 541
|
Posted: Mon May 24, 2010 3:32 pm Post subject: Re: Include doesn't work... |
|
|
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 |
|
leonarth Smarty n00b
Joined: 24 May 2010 Posts: 4
|
Posted: Mon May 24, 2010 5:49 pm Post subject: |
|
|
Still doesn't work. Any other idea? |
|
Back to top |
|
douglassdavis Smarty Junkie
Joined: 21 Jan 2008 Posts: 541
|
Posted: Mon May 24, 2010 5:51 pm Post subject: |
|
|
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon May 24, 2010 6:34 pm Post subject: |
|
|
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 |
|
leonarth Smarty n00b
Joined: 24 May 2010 Posts: 4
|
Posted: Mon May 24, 2010 6:41 pm Post subject: |
|
|
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon May 24, 2010 6:49 pm Post subject: |
|
|
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 |
|
leonarth Smarty n00b
Joined: 24 May 2010 Posts: 4
|
Posted: Mon May 24, 2010 7:25 pm Post subject: |
|
|
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon May 24, 2010 7:50 pm Post subject: |
|
|
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 |
|
|