View previous topic :: View next topic |
Author |
Message |
krone Smarty Rookie
Joined: 17 Apr 2013 Posts: 6
|
Posted: Wed Apr 17, 2013 7:57 am Post subject: Navigation bar |
|
|
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed Apr 17, 2013 1:24 pm Post subject: |
|
|
Here is one strategy: in your URL link put:
then in your PHP:
Code: | $smarty->assign('page',$_GET['page']); |
Then in your template:
Code: | {include file="$page.tpl"} |
|
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed Apr 17, 2013 1:25 pm Post subject: |
|
|
mohrt wrote: | Here is one strategy: in your URL link put:
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 |
|
krone Smarty Rookie
Joined: 17 Apr 2013 Posts: 6
|
Posted: Thu Apr 18, 2013 5:35 am Post subject: |
|
|
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Apr 18, 2013 1:41 pm Post subject: |
|
|
$_GET['page'] has no value, so you didn't have ?page=foo in your URL. |
|
Back to top |
|
krone Smarty Rookie
Joined: 17 Apr 2013 Posts: 6
|
Posted: Fri Apr 19, 2013 9:14 am Post subject: |
|
|
i've solved the problem.
the code just needed some isset and emty logic combined with some if statements. |
|
Back to top |
|
krone Smarty Rookie
Joined: 17 Apr 2013 Posts: 6
|
Posted: Fri Apr 19, 2013 10:40 am Post subject: |
|
|
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Fri Apr 19, 2013 4:09 pm Post subject: |
|
|
Code: | $page = $_GET['page'];
$smarty->display("{$page}.tpl"); |
Keep in mind, sanitize your _GET variables first. |
|
Back to top |
|
|