garrettheel Posted August 6, 2008 Share Posted August 6, 2008 Okay, nobody seems to be able to help me in the other place so I'll ask here. I am new to the smarty template system and would really appreciate some help in modifying a theme I’m making. The first question I have is how to define different sidebar settings for different pages.. E.g on the home page I do not want any sidebars and on the products page I want the left side bar. How can I change which sidebars appear on which pages? I will post any more questions I have in here as I come across them.Also, what is the smarty way of outputting each of the categories and the id for them so I can linke.g {foreach $category}{$category_name}{/foreach}I’d really appreciate the help! Thanks Link to comment Share on other sites More sharing options...
ejectcore Posted August 6, 2008 Share Posted August 6, 2008 first off if your starting a new theme my advice would be to do your own CSSuse some of the current css in global.css then create you own styles in a new defined style sheetAs well as developing modules I am currently working on 2-3 bespoke themes for members on hereif you want to do it yourself I can advice you, otheriwse I can do this for you for a small feeeither provide your own concept or I will work on a new graphics design concept the choice is yoursPM if you need me ;-) Link to comment Share on other sites More sharing options...
garrettheel Posted August 7, 2008 Author Share Posted August 7, 2008 Thanks for your reply. I'm not interested in paying as I am a developer and am customizing a Prestashop template. I would just like some help with how to define which pages have which sidebars and the smarty way of outputting categories. This is only a couple of lines of code and I think it will be very easy for someone who knows how to do it. Link to comment Share on other sites More sharing options...
ejectcore Posted August 7, 2008 Share Posted August 7, 2008 Do you want the catgegory to relate using $_GET['id_category'] :question: Link to comment Share on other sites More sharing options...
ejectcore Posted August 7, 2008 Share Posted August 7, 2008 If you can explain clearly what your trying to do possibly provide visuals I will try to help out the best way I can ;-) Link to comment Share on other sites More sharing options...
garrettheel Posted August 7, 2008 Author Share Posted August 7, 2008 Okay here's an example of the home page.http://img.skitch.com/20080807-1x1yd43gmgk7ei54tqrirwnh5u.jpgAs you can see from the picture, I want to remove the sidebars (both of them) only on the front page. I know this is done by removing the {HOOK_LEFT} stuff but that is kept in the header which is used on all pages, is there some code I can use to remove the sidebars from only pages I specify? E.g the index.tpl page.Secondly, I just want to know the way to output a list of categories and the way to output a list of sub categories and their ID, like in the example I gave before. Something like {foreach $category} and then I can do {$category} and then link it to the actual category with Thanks Link to comment Share on other sites More sharing options...
ejectcore Posted August 7, 2008 Share Posted August 7, 2008 OK I will break this down into stages1) All template files (tpl) are defined in there corrosponding php filesLets take a section of code from the block catgeories module for example:- $rootCateg = Category::getRootCategory(); $blockCategTree = $rootCateg->recurseLiteCategTree(intval(Configuration::get('BLOCK_CATEG_MAX_DEPTH'))); $isDhtml = (Configuration::get('BLOCK_CATEG_DHTML') == 1 ? true : false); if (isset($_GET['id_category'])) $smarty->assign('currentCategoryId', intval($_GET['id_category'])); $smarty->assign('blockCategTree', $blockCategTree); $smarty->assign('branche_tpl_path', _PS_MODULE_DIR_.'blockcategories/category-tree-branch.tpl'); $smarty->assign('isDhtml', $isDhtml); To break this down what we have is :-Most functions are first defined to use with Pretsahop in the Classes directorya) $rootCateg = Category::getRootCategory(); now this will fetch all the catgeories from the getRootCategory function located on line 432 in classes/category.php (all functions related to catgeories can be found here & called upon anywhere within PrestashopAs you know the string $rootCateg is just a name you choose to define this function.$blockCategTree = $rootCateg->recurseLiteCategTree(intval(Configuration::get('BLOCK_CATEG_MAX_DEPTH')));what this does is fetches all subcategories defined by our first function again this function can be located line 128 in classes/category.phpfunction recurseLiteCategTree($maxDepth = 3)notice intval(Configuration::get('BLOCK_CATEG_MAX_DEPTH')) takes this value from the admin configurationdoing this manually would also work $blockCategTree = $rootCateg->recurseLiteCategTree(2); // (shows maximum depth of catgeories to be 2)Once you understand the way functions & the classes work everything else should be straight forward ;-) c) if (isset($_GET['id_category'])) This one expalins it self Now on to the smarty template engine $smarty->assign('currentCategoryId', intval($_GET['id_category'])); $smarty->assign('blockCategTree', $blockCategTree); $smarty->assign('branche_tpl_path', _PS_MODULE_DIR_.'blockcategories/category-tree-branch.tpl');All we are doing here is defining the php varible to smartycurrentCategoryId enclosed by single speech marks is the name you wish to set for you php variable to be calledyou then need a comma & space then all you do is enter your php variable followed by the semi colon as you usely do in PHPI will go through the template stage with you later hopefully this is a good starting point for youAlso i think the easiest method for hiding column would be using exceptions.Unfortuntly there is no current way to edit these once set without trnasplanting the module & setting up the exceptions unless you want to play around with the DB is which case you will find them located ps_hook_module_exceptions Hope this helps ;-) Link to comment Share on other sites More sharing options...
garrettheel Posted August 7, 2008 Author Share Posted August 7, 2008 Hi, thanks for your help. THe ps hook module exceptions was what I was looking for thanks, I've got that worked out now.Now I just need to fix up the other things.. I can't find a variable that I can use in the blockcategories module that will get me the subcategories of ONLY the current main category (e.g Home->iPods from the default install). I only want the subcategories for the current active category. How can I do this? I couldn't seem to get it from what you posted.Also, in the header.tlp I need a variable that will get me all of the main categories (like iPods again) and their corresponding links so I can put it in the navigation. I wish I had time to get my hands dirty with smarty but I have a pretty tight deadline to have this project completed and I just need to get a few things working so it'd be a huge help if anyone could tell me these things. Link to comment Share on other sites More sharing options...
ejectcore Posted August 7, 2008 Share Posted August 7, 2008 You will be better off creating a module instead of putting this in header.tpl & then assign this to Hook Topyou PHP will be no good without modifying the template files.Please post you current cose & possibly a visual so I can see what your actually tring to acheive here ;-) Link to comment Share on other sites More sharing options...
ejectcore Posted August 7, 2008 Share Posted August 7, 2008 This is infact the variable used for sub categories, there are a few other options which you can look up in classes/category.phpbut if you use $blockCategTree = $rootCateg->recurseLiteCategTreethen just do something like this in your template file again this would be better as a sepearate module{foreach from=$blockCategTree.children item=child name=blockCategTree}you template code here ...{/foreach} Link to comment Share on other sites More sharing options...
garrettheel Posted August 7, 2008 Author Share Posted August 7, 2008 Well I need to be able to get the categories in the header.tlp so that I can add all of the main categories to my menu. Which file do I need to assign the variable to in order to access the categories from the header.tlp file?I don't have the code with me right now, I'll get it for you when I get home in a few hours but here's a picture with some details on how I want to do things.http://img361.imageshack.us/img361/1413/prestahh8.jpg Link to comment Share on other sites More sharing options...
garrettheel Posted August 8, 2008 Author Share Posted August 8, 2008 Okay, I've solved one of my problems with getting all the categories for the menu. All I need to know is where to assign a variable so I can make it available in my header.tlp file. (No, I'm not interested in making a module for the header, I just need something small and a module is overkill). So where can I put the $smarty->assign() code so that it is available in header.tlp?Thanks! Link to comment Share on other sites More sharing options...
ejectcore Posted August 8, 2008 Share Posted August 8, 2008 I have never tried this from the header but I guess you would insert yur code in header.phpalso looking at your visual the center column does not stretch across the homepage this shoudl help youfor example we want 2 columns on the homepage then 3 on the rest of the pagesheader.tpl {if $page_name == "index"}{/if} {if $page_name != "index"}{/if} Link to comment Share on other sites More sharing options...
garrettheel Posted August 8, 2008 Author Share Posted August 8, 2008 Hi, thanks for your reply. I figured I would use a header.php file, but I was wondering what I would need to put in it.E.g what would it look like?<?phpclass something? extends something? {function __construct() {smarty->assign();}is that the basic structure of the header.php file that I'll need to make? Link to comment Share on other sites More sharing options...
ejectcore Posted August 8, 2008 Share Posted August 8, 2008 here's an example from my latest module to fetch the catgeories <?php class CategoriesBar extends Module { function __construct() { $this->name = 'categoriesbar'; $this->tab = 'Blocks'; $this->version = 0.1; // Module created by Alpha Media 05/08/08 parent::__construct(); /* The parent construct is required for translations */ $this->page = basename(__FILE__, '.php'); $this->displayName = $this->l('Top Categories Bar'); $this->description = $this->l('Adds a Bar featuring product categories'); } function install() { if (!parent::install()) return false; if (!$this->registerHook('top')) return false; return true; } /** * Returns module content for header * * @param array $params Parameters * @return string Content */ function hookTop($params) { global $smarty; //construct categories $depth = 1; $rootCateg = Category::getRootCategory()->recurseLiteCategTree($depth); if (isset($_GET['id_category'])) $smarty->assign('currentCategoryId', intval($_GET['id_category'])); $smarty->assign('bar_tpl_path', _PS_MODULE_DIR_.'categoriesbar/category-bar-level.tpl'); $smarty->assign('categoriesLevel', $rootCateg); return $this->display(__FILE__, 'categoriesbar.tpl'); } } ?> It much easier to create & assign a module!the code above is not finished & please no one try to use this as the full module zip will be avialble next week roll: Hope that helps : Link to comment Share on other sites More sharing options...
garrettheel Posted August 8, 2008 Author Share Posted August 8, 2008 Ah, a module is too complex for me at the moment. I only have a short amount of time so I want to do it the simplest way possible. Here's my header.php file <?php class Categories extends whatgoeshere? { __construct() { global $smarty $smarty->assign('test', 'test'); } } ?> Basically, this is just so that I can put {$test} in my header.tlp and it will work. Can you show me what to do so this will work? Link to comment Share on other sites More sharing options...
ejectcore Posted August 8, 2008 Share Posted August 8, 2008 You already have $smarty->assign so you need to add to the array no need to create a new class, this is really only used for module creation $test = 'categories test'; $smarty->assign(array( 'HOOK_HEADER' => Module::hookExec('header'), 'HOOK_LEFT_COLUMN' => Module::hookExec('leftColumn'), 'HOOK_TOP' => Module::hookExec('top'), 'test' => $test, 'static_token' => Tools::getToken(false), 'token' => Tools::getToken() )); Link to comment Share on other sites More sharing options...
garrettheel Posted August 8, 2008 Author Share Posted August 8, 2008 I added that code to header.php and I still couldn't get the smarty variable in my header.tlp using {$test} Any more ideas?Edit: Also, I think smarty is not seeing the header.php file, perhaps there's some extra code I have to add somewhere? Because when I just put some plain html in the header.php it doesn't show up on the page like it should. Link to comment Share on other sites More sharing options...
ejectcore Posted August 8, 2008 Share Posted August 8, 2008 it works this end :roll: Make sure you type this in the same case for both template & the php page because this will be case sensitive if this still doesn't work please post your header.php code & also a snippet from your header.tpl Link to comment Share on other sites More sharing options...
garrettheel Posted August 8, 2008 Author Share Posted August 8, 2008 Hmm, it's the same case..These are the files: (they are both in the same directory in /themes/theme_name/)PS - you can see where i've called the test variable just after the end of the head tag </head>header.php <?php $test = 'categories test'; $smarty->assign(array( 'HOOK_HEADER' => Module::hookExec('header'), 'HOOK_LEFT_COLUMN' => Module::hookExec('leftColumn'), 'HOOK_TOP' => Module::hookExec('top'), 'test' => $test, 'static_token' => Tools::getToken(false), 'token' => Tools::getToken() )); ?> header.tpl <?php <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="{$lang_iso}"> <head> <base href="{$protocol}{$smarty.server.HTTP_HOST|escape:'htmlall':'UTF-8'}{$base_dir}" /> <title>{$meta_title|escape:'htmlall':'UTF-8'}</title> {if isset($meta_description) AND $meta_description} <meta name="description" content="{$meta_description|escape:htmlall:'UTF-8'}" /> {/if} {if isset($meta_keywords) AND $meta_keywords} <meta name="keywords" content="{$meta_keywords|escape:htmlall:'UTF-8'}" /> {/if} <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" /> <meta name="robots" content="{if isset($nobots)}no{/if}index,follow" /> <link rel="shortcut icon" href="{$img_dir}favicon.ico" /> {if isset($css_files)} {foreach from=$css_files key=css_uri item=media} <link href="{$css_uri}" rel="stylesheet" type="text/css" media="{$media}" /> {/foreach} {/if} //global JS variable var baseDir = '{$base_dir}'; var static_token = '{$static_token}'; var token = '{$token}'; {if isset($js_files)} {foreach from=$js_files item=js_uri} {/foreach} {/if} {$HOOK_HEADER} </head> {$test} <body {if $page_name}id="{$page_name|escape:'htmlall':'UTF-8'}"{/if}> <!-- Header --> {$HOOK_TOP} Hjem Om oss Kontakt oss Specials Checkout <!-- Left --> {$HOOK_LEFT_COLUMN} <!-- Center --> ?> Link to comment Share on other sites More sharing options...
ejectcore Posted August 8, 2008 Share Posted August 8, 2008 Where is your test variable in header.tpl :question: try putting it somewhere like this {$test} {$HOOK_LEFT_COLUMN} Link to comment Share on other sites More sharing options...
garrettheel Posted August 8, 2008 Author Share Posted August 8, 2008 It's already there Look just past half way after the HOOK_HEADER Link to comment Share on other sites More sharing options...
ejectcore Posted August 8, 2008 Share Posted August 8, 2008 I see but it's not in your body :wow: Link to comment Share on other sites More sharing options...
garrettheel Posted August 8, 2008 Author Share Posted August 8, 2008 I just put it in various different places in the header.tpl file and still nothing. i think it's a problem with smarty not seeing the header.php file, I feel like there must be some code that must be added because putting plain html in the header.php file doesn't output either.. Link to comment Share on other sites More sharing options...
ejectcore Posted August 8, 2008 Share Posted August 8, 2008 No it defferently works for me :roll: Here's what your header.php should look like <?php require_once(dirname(__FILE__).'/init.php'); /* CSS */ $css_files[_THEME_CSS_DIR_.'global.css'] = 'all'; $test = 'categories test'; /* Hooks are volontary out the initialize array (need those variables already assigned) */ $smarty->assign(array( 'test' => $test, 'HOOK_HEADER' => Module::hookExec('header'), 'HOOK_LEFT_COLUMN' => Module::hookExec('leftColumn'), 'HOOK_TOP' => Module::hookExec('top'), 'static_token' => Tools::getToken(false), 'token' => Tools::getToken() )); if(isset($css_files) AND !empty($css_files)) $smarty->assign('css_files', $css_files); if(isset($js_files) AND !empty($js_files)) $smarty->assign('js_files', $js_files); /* Display a maintenance page if shop is closed */ if (isset($maintenance)) { header('HTTP/1.1 503 temporarily overloaded'); $smarty->display(_PS_THEME_DIR_.'maintenance.tpl'); exit; } $smarty->display(_PS_THEME_DIR_.'header.tpl'); ?> Link to comment Share on other sites More sharing options...
ejectcore Posted August 8, 2008 Share Posted August 8, 2008 Why are you using php code blocks within the template files when header.php has already defined the variables :question: Link to comment Share on other sites More sharing options...
garrettheel Posted August 8, 2008 Author Share Posted August 8, 2008 what are you talking about? I created my own header.php file because one didn't exist in the template directory Link to comment Share on other sites More sharing options...
ejectcore Posted August 8, 2008 Share Posted August 8, 2008 No don't do that! You are suppose to use the one found in the root all template files relate to php files found in the root no wonder it doesn't work for you :roll: Link to comment Share on other sites More sharing options...
garrettheel Posted August 8, 2008 Author Share Posted August 8, 2008 ah, got it! haha, i tried to create my own header.php (why i thought more code had to be added) in the template directory Link to comment Share on other sites More sharing options...
garrettheel Posted August 8, 2008 Author Share Posted August 8, 2008 Okay, now I just need help with one more thing. This is what I was talking about before, I need a variable that will get me all the children for the current category. E.g if the url has id_category=3, then this variable will have all of the children for variable 3 in it. Can this be done? Link to comment Share on other sites More sharing options...
ejectcore Posted August 8, 2008 Share Posted August 8, 2008 try something like this in your header.phpalthough this is what i use for my module may need some tweakinghave you ever worked with smarty before & used FOREACH statementsIf not you will stuggle with this :roll: $test = 'categories test'; $depth = 2; $rootCateg = Category::getRootCategory()->recurseLiteCategTree($depth); if (isset($_GET['id_category'])) $smarty->assign('currentCategoryId', intval($_GET['id_category'])); $smarty->assign('sub_tpl_path', _PS_MODULE_DIR_.'categoriesbar/category-bar-level.tpl'); $smarty->assign('categoriesLevel', $rootCateg); /* Hooks are volontary out the initialize array (need those variables already assigned) */ $smarty->assign(array( 'test' => $test, 'HOOK_HEADER' => Module::hookExec('header'), 'HOOK_LEFT_COLUMN' => Module::hookExec('leftColumn'), 'HOOK_TOP' => Module::hookExec('top'), 'static_token' => Tools::getToken(false), 'token' => Tools::getToken() )); if (isset($_GET['id_category'])) $smarty->assign('currentCategoryId', intval($_GET['id_category'])); $smarty->assign('bar_tpl_path', _PS_MODULE_DIR_.'categoriesbar/category-bar-level.tpl'); $smarty->assign('categoriesLevel', $rootCateg); return $this->display(__FILE__, 'categoriesbar.tpl'); }}?> Link to comment Share on other sites More sharing options...
Recommended Posts