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

Need help {if}{else}{/if} in tpl files

 
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
kingnalz
Smarty Rookie


Joined: 21 Aug 2013
Posts: 11

PostPosted: Sat Aug 24, 2013 6:02 am    Post subject: Need help {if}{else}{/if} in tpl files Reply with quote

I just write Php code at index.php
Code:

global $_GET;
global $_POST;
$get = $_GET;
$post = $_POST;
$frm = array_merge ($get, $post);

global $ENV;
global $SERVER;
$frm_env = array ();
$frm_env = array_merge ($_ENV, $_SERVER);


I need to setup navigation use one header.tpl only.

Navigation link in the main is www.mysite.com is
Code:

<ol id="list-nav">
     <li><a href="">Home</a></li>
     <li><a href="price">Price List</a></li>
     <li><a href="termcond">Term & Cond</a></li>
     <li><a href="contactus">Contact Us</a></li>
</ol>


The all price, termcond, and contacus I put in other folder,
eg, price link is www.mysite.com/price so its navigation for price will be
Code:

<ol id="list-nav">
     <li><a href="../">Home</a></li>
     <li><a href="../price">Price List</a></li>
     <li><a href="../termcond">Term & Cond</a></li>
     <li><a href="../contactus">Contact Us</a></li>
</ol>


Please help me to set {if}{else} using all this code.

and other things I notice need to change the CSS & Images Folder link using this statement too.

Thank You.
**Sorry for my bad English.
Back to top
View user's profile Send private message
kingnalz
Smarty Rookie


Joined: 21 Aug 2013
Posts: 11

PostPosted: Sat Aug 24, 2013 12:22 pm    Post subject: Reply with quote

I try this and working,
But A messy header.tpl I get because need to copy a lot under {if} condition and {else} condition;

PHP;
Code:

$firstUrl = $_SERVER['HTTP_HOST'];
$secondUrl = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];


header.tpl
Code:

{if $firstUrl eq $secondUrl}
<ol id="list-nav">
        <li><a href="">Home</a></li>
        <li><a href="price">Price List</a></li>
        <li><a href="termcond">Term & Cond</a></li>
        <li><a href="contactus">Contact Us</a></li>
 </ol>
{else}
<ol id="list-nav">
        <li><a href="../">Home</a></li>
        <li><a href="../price">Price List</a></li>
        <li><a href="../termcond">Term & Cond</a></li>
        <li><a href="../contactus">Contact Us</a></li>
</ol>
{/if}


So now my Question is change to other,
Because if we put php files in diffrent folder to make the url different,
eg. http://www.mysite.com/aboutus
eg. http://www.mysite.com/contact
so, its make to write the Header.tpl to calling the CSS, Images, JavaScript in the different Url.
eg, http://www.mysite.com/ is href="css/style.css"
eg. http://www.mysite.com/aboutus is href=''../css/style.css"

So how to set absoulute path (mybe setting for smarty) that wherever condition or whatever folder we put in same server, its still can calling all this three url in the same link. like we setting the the template folder.

Sorry because in Noobies.
Thank You.
Back to top
View user's profile Send private message
kingnalz
Smarty Rookie


Joined: 21 Aug 2013
Posts: 11

PostPosted: Sat Aug 24, 2013 12:46 pm    Post subject: Reply with quote

Declare in php;

Code:


$firstUrl = $_SERVER['HTTP_HOST'];
$secondUrl = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];


Im get few idea, using the {$firstUrl} infront all link but its also not work.

Code:

<img src="{$firstUrl}/images/1.png">
<<link href="{$firstUrl}/style.css" rel="stylesheet" type="text/css" media="screen" />


Any other method ?
Back to top
View user's profile Send private message
kingnalz
Smarty Rookie


Joined: 21 Aug 2013
Posts: 11

PostPosted: Sat Aug 24, 2013 1:05 pm    Post subject: Reply with quote

Resolve for calling CSS and Images.
But the the problem now is JavaScript not working.

code chage in php;

Code:

$firstUrl = 'http://'.$_SERVER['HTTP_HOST'];
$secondUrl = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];


in tpl;
Code:

<img src="{$firstUrl}/images/1.png">  <!-- Working -->
<link href="{$firstUrl}/style.css" rel="stylesheet" type="text/css" media="screen" />  <!-- Working -->

<script type="text/javascript" src="{$firstUrl}/js/Java.js"></script>   <!-- Not Working -->


other suggestion?
Back to top
View user's profile Send private message
kingnalz
Smarty Rookie


Joined: 21 Aug 2013
Posts: 11

PostPosted: Sat Aug 24, 2013 1:11 pm    Post subject: Reply with quote

All solve,

Need to call javascript src/link outside the {literal}{/literal}.
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