|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
hank Smarty n00b
Joined: 30 Jun 2007 Posts: 2
|
Posted: Sat Jun 30, 2007 11:33 pm Post subject: Strona glowna i podstrony w Smarty |
|
|
Witam,
probuje przerobic swoja strone, aby korzystala z szablonow i zastanawiam sie nad jakims wygodnym sposobem dolaczania tresci wybranej podstrony do strony glownej. W czystym php inkludowalem potrzebne podtsrony przy pomocy switch($_GET['page']), gdy dolaczylem Smarty, kod z pliku index.php wyglada tak:
Code: |
switch ($_GET['page'])
{
case 'add':
include 'add.php';
$output = $smarty->fetch('add.tpl');
break;
case 'search':
include 'search.php';
$output = $smarty->fetch('search.tpl');
break;
case 'edit':
include 'edit.php';
$output = $smarty->fetch('edit.tpl');
break;
case 'urls':
include 'urls.php';
$output = $smarty->fetch('urls.tpl');
break;
case 'panel':
include 'panel.php';
$output = $smarty->fetch('panel.tpl');
break;
case 'status':
include 'status.php';
$output = $smarty->fetch('status.tpl');
break;
case 'main':
default:
include 'main.php';
$output = $smarty->fetch('main.tpl');
break;
}
// przyporzadkowanie tresci podstrony pod zmienna
$smarty->assign('contentpage', $output);
// pokazanie strony
$smarty->display('index.tpl'); |
W pliku index.tpl uzywam {$contentpage} w miejscu, gdzie ma sie pojawic tresc wybranej podstrony. Tyle tylko, ze takie rozwiazanie jest raczej malo zgrabne. Jest jakis sposob zeby zrobic to prosciej?? |
|
Back to top |
|
hank Smarty n00b
Joined: 30 Jun 2007 Posts: 2
|
Posted: Sat Jul 07, 2007 1:41 pm Post subject: |
|
|
Naprawde nikt nie ma zadnego pomyslu? |
|
Back to top |
|
_mosh Smarty n00b
Joined: 02 Aug 2007 Posts: 1
|
Posted: Fri Aug 03, 2007 9:34 am Post subject: |
|
|
heja
ja to moze bym tak zrobi? w Twojej sytuacji:
Code: |
$modul = $_GET['page'];
if (file_exists("_mod/moduly/$modul.php")) include("_mod/moduly/$modul.php");
$modul_temp = $smarty->fetch("$modul.tpl");
$smarty->assign("$modul", $modul_temp);
|
i to chyba na tyle
dalem tam 'czy istnieje' bo mialem tak u siebie ze czasem ladowal wczesniej php a czasem sam tpl tylko
pozdro _________________ polski CMS przyjazny pozycjonowaniu SEO CMS oparty na smarty. Forum dyskusyjne na vB |
|
Back to top |
|
Unk Smarty n00b
Joined: 24 Mar 2011 Posts: 2
|
Posted: Thu Mar 24, 2011 2:34 pm Post subject: |
|
|
Miałem podobny problem, wzorowałem się na odpowiedzi _mosh'a, warto ją jednak rozbudować w przypadku gdy podstrona nie ma przypisanego modulu php, a jedynie szablon tpl:
Code: |
<?php
require_once('Smarty/Smarty.class.php');
$smarty = new Smarty();
// dodatkowa katalogi na templaty, cache, configi
$smarty->template_dir = 'templates/';
$smarty->compile_dir = 'SmartyCCT/templates_c/';
$smarty->cache_dir = 'SmartyCCT/cache/';
$smarty->config_dir = 'SmartyCCT/configs/';
if (isset($_GET['page'])){
$module = basename($_GET['page']);
if (file_exists("$module.php")) include("$module.php");
if (file_exists($smarty->template_dir.$module.".tpl")) $body_template = "$module.tpl";
else $body_template = 'welcome.tpl';
}
else $body_template = 'welcome.tpl';
$smarty->assign('body',$body_template);
$smarty->display('index.tpl');
?>
|
A w szablonie index.tpl wystarczy w odpowiednim miejscu dać:
Code: | {include file=$body} |
Być może to rozwiązanie komuś się jeszcze przyda. |
|
Back to top |
|
|
|
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
|