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

Navigation bar

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


Joined: 17 Apr 2013
Posts: 6

PostPosted: Wed Apr 17, 2013 7:57 am    Post subject: Navigation bar Reply with quote

Hello. I am new at Smarty and i have a newbie question.

How can i make navigation that will show requested tpl file inside index.php (or index.tpl) when you click on navigation link?

Tnx
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Wed Apr 17, 2013 1:24 pm    Post subject: Reply with quote

Here is one strategy: in your URL link put:

Code:
?page=mypage


then in your PHP:

Code:
$smarty->assign('page',$_GET['page']);


Then in your template:

Code:
{include file="$page.tpl"}
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 Apr 17, 2013 1:25 pm    Post subject: Reply with quote

mohrt wrote:
Here is one strategy: in your URL link put:

Code:
?page=mypage


then in your PHP:

Code:
$smarty->assign('page',$_GET['page']);


Then in your template:

Code:
{include file="$page.tpl"}


That would include mypage.tpl in your template.
Back to top
View user's profile Send private message Visit poster's website
krone
Smarty Rookie


Joined: 17 Apr 2013
Posts: 6

PostPosted: Thu Apr 18, 2013 5:35 am    Post subject: Reply with quote

thank you, but it returns me an error.
Undefined index: $smarty->assign('page',$_GET['page']);

Don't know why it say it is undefined
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Thu Apr 18, 2013 1:41 pm    Post subject: Reply with quote

$_GET['page'] has no value, so you didn't have ?page=foo in your URL.
Back to top
View user's profile Send private message Visit poster's website
krone
Smarty Rookie


Joined: 17 Apr 2013
Posts: 6

PostPosted: Fri Apr 19, 2013 9:14 am    Post subject: Reply with quote

i've solved the problem.
the code just needed some isset and emty logic combined with some if statements.
Back to top
View user's profile Send private message
krone
Smarty Rookie


Joined: 17 Apr 2013
Posts: 6

PostPosted: Fri Apr 19, 2013 10:40 am    Post subject: Reply with quote

i have another question about this post.

now i have to make same thing without index.tpl, so it would read it deretcly from index.php. don't know what else should i try, becaouse i've tride almost everything.
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Fri Apr 19, 2013 4:09 pm    Post subject: Reply with quote

Code:
$page = $_GET['page'];
$smarty->display("{$page}.tpl");


Keep in mind, sanitize your _GET variables first.
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 -> 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