Truemedia Posted September 23, 2010 Share Posted September 23, 2010 Hi, I'm not completely new to smarty although I have so far only done very simple stuff. I am trying to add css dynamically through inline styling in html attributes (example My words).I already have a script setup to automatically deal with some default styling with an array but I want either the first or last key of the array to have modified width. {if $url} {$title} {else} {$title} {/if} {foreach from=$blocklink_links item=blocklink_link} {$blocklink_link.$lang} {/foreach} I realize people will suggest use css stylesheets but inline styling is most suited for the application of this code. Is there any smary equivalent to: foreach($array as $key => $value) { if($key == "speacialKey") { <html></html> } } I tried posting this in the smarty forum but anywhere I try to post I get "The topic or post you requested does not exist" > WHY?Any help appreciated thanks Link to comment Share on other sites More sharing options...
MrBaseball34 Posted September 23, 2010 Share Posted September 23, 2010 Is there any smary equivalent to: foreach($array as $key => $value) { if($key == "speacialKey") { <html></html> } } http://www.smarty.net/manual/en/language.function.foreach.phpExample 7-6. Demonstrates the item and key attributes Link to comment Share on other sites More sharing options...
Truemedia Posted September 23, 2010 Author Share Posted September 23, 2010 Cheerz , although while I was messing around I tried hooking a header css file and it didn't show up.Any idea why it doesn't work? This is the code I've code for tryna add a css file public function install() { if (parent::install() == false OR $this->registerHook('header') == false OR $this->registerHook('top') == false) return false; $query = 'CREATE TABLE '._DB_PREFIX_.'blocklink (`id_link` int(2) NOT NULL AUTO_INCREMENT, `url` varchar(255) NOT NULL, new_window TINYINT(1) NOT NULL, PRIMARY KEY(`id_link`)) ENGINE=MyISAM default CHARSET=utf8'; if (!Db::getInstance()->Execute($query)) return false; $query = 'CREATE TABLE '._DB_PREFIX_.'blocklink_lang (`id_link` int(2) NOT NULL, `id_lang` int(2) NOT NULL, `text` varchar(64) NOT NULL, PRIMARY KEY(`id_link`, `id_lang`)) ENGINE=MyISAM default CHARSET=utf8'; if (!Db::getInstance()->Execute($query)) return false; return (Configuration::updateValue('PS_BLOCKLINK_TITLE', array('1' => 'Block link', '2' => 'Bloc lien')) AND Configuration::updateValue('PS_BLOCKLINK_TITLE', '')); } function hookHeader($params) { global $smarty, $cookie; $smarty->assign(array( 'menuCssUrl' => 'http://'.Tools::getHttpHost(false, true).__PS_BASE_URI__.'modules/'.$this->name.'/css/mainmenu.css', )); return $this->display(__FILE__, 'header.tpl'); } Link to comment Share on other sites More sharing options...
MrBaseball34 Posted September 23, 2010 Share Posted September 23, 2010 I have no idea, Did you modify header.tpl to actually load the CSS from the array? Link to comment Share on other sites More sharing options...
Truemedia Posted September 23, 2010 Author Share Posted September 23, 2010 nah the header.tpl just has this code <link rel="stylesheet" href="{$directory_substitute}mycss.css" /> Which is independent from conditional array key method Link to comment Share on other sites More sharing options...
MrBaseball34 Posted September 23, 2010 Share Posted September 23, 2010 Well, how do you expect the CSS to be loaded in the header.tpl, then? Link to comment Share on other sites More sharing options...
Truemedia Posted September 23, 2010 Author Share Posted September 23, 2010 Well theres a hookheader that adds the smarty code to load header.tpl. But when I view the source of a frontoffice page the "<link>" is nowhere to be found apart from the ones there by default.I'll post the code for that later, not on a computer ATM. Link to comment Share on other sites More sharing options...
rocky Posted September 24, 2010 Share Posted September 24, 2010 The Smarty equivalent of: foreach($array as $key => $value) if($key == "specialKey") <html></html> is: {foreach from=$array key=key item=value} {if $key == "specialKey"} <html></html> {/if} {/foreach} You can also get the first item without knowing the key like this: {foreach from=$array item=value name=loop} {if $smarty.foreach.loop.first} <html></html> {/if} {/foreach} and the following to get the last item without knowing the key: {foreach from=$array item=value name=loop} {if $smarty.foreach.loop.last} <html></html> {/if} {/foreach} You can give the foreach loop any name you like. Link to comment Share on other sites More sharing options...
Truemedia Posted September 24, 2010 Author Share Posted September 24, 2010 Thanks guys, this the code I was trying to use to load css file but didn't work.This is from the module hook: function hookHeader($params) { global $smarty, $cookie; $smarty->assign(array( 'menuCssUrl' => 'http://'.Tools::getHttpHost(false, true).__PS_BASE_URI__.'modules/'.$this->name.'/css/mainmenu.css', )); return $this->display(__FILE__, 'header.tpl'); } then this is the header tpl file: <link rel="stylesheet" type="text/css" href="{$menuCssUrl}css/mainmenu.css" /> and this is the install function of the module: public function install() { if (parent::install() == false OR $this->registerHook('header') == false OR $this->registerHook('top') == false) return false; $query = 'CREATE TABLE '._DB_PREFIX_.'blocklink (`id_link` int(2) NOT NULL AUTO_INCREMENT, `url` varchar(255) NOT NULL, new_window TINYINT(1) NOT NULL, PRIMARY KEY(`id_link`)) ENGINE=MyISAM default CHARSET=utf8'; if (!Db::getInstance()->Execute($query)) return false; $query = 'CREATE TABLE '._DB_PREFIX_.'blocklink_lang (`id_link` int(2) NOT NULL, `id_lang` int(2) NOT NULL, `text` varchar(64) NOT NULL, PRIMARY KEY(`id_link`, `id_lang`)) ENGINE=MyISAM default CHARSET=utf8'; if (!Db::getInstance()->Execute($query)) return false; return (Configuration::updateValue('PS_BLOCKLINK_TITLE', array('1' => 'Block link', '2' => 'Bloc lien')) AND Configuration::updateValue('PS_BLOCKLINK_TITLE', '')); } Any ideas? IF I can fix this today I will be able to sell my menu almost straight away and introduce a css editor in a future update. Link to comment Share on other sites More sharing options...
MrBaseball34 Posted September 24, 2010 Share Posted September 24, 2010 I don' t see what the installation code has to do with it or why you are posting it.Also, have you placed {debug} in header.tpl to see if your variable {$menuCssUrl} is set? Link to comment Share on other sites More sharing options...
MrBaseball34 Posted September 24, 2010 Share Posted September 24, 2010 Also, your variable is being set to: 'http://'.Tools::getHttpHost(false, true).__PS_BASE_URI__.'modules/'.$this->name.'/css/mainmenu.css' and you are trying to load: "{$menuCssUrl}css/mainmenu.css" You already have "css/mainmenu.css" in the variable, why you appending it to the variable in the tpl?I think I also see an extra comma in the assignment, the comma after '/css/mainmenu.css' is not needed: Link to comment Share on other sites More sharing options...
Truemedia Posted September 24, 2010 Author Share Posted September 24, 2010 didn't notice extra suffix sorry lol. But the (<link rel="") doesnt even show up as wrong, just doesn't show up. Link to comment Share on other sites More sharing options...
MrBaseball34 Posted September 24, 2010 Share Posted September 24, 2010 I don't know what you are doing wrong because it works for me. I placed your code in blocksearch.php and the link in header.tpl and it worked perfectly. Link to comment Share on other sites More sharing options...
Truemedia Posted September 25, 2010 Author Share Posted September 25, 2010 Nah still doesn't work, this is the source from the head when viewing store front: <head> <title>MCO Store</title> <meta name="description" content="Shop powered by PrestaShop" /> <meta name="keywords" content="shop, prestashop" /> <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" /> <meta name="generator" content="PrestaShop" /> <meta name="robots" content="index,follow" /> <link rel="icon" type="image/vnd.microsoft.icon" href="http://localhost/prestashop/img/favicon.ico" /> <link rel="shortcut icon" type="image/x-icon" href="http://localhost/prestashop/img/favicon.ico" /> <link href="/prestashop/themes/prestashop/css/global.css" rel="stylesheet" type="text/css" media="all" /> [removed][removed] [removed] var baseDir = 'http://localhost/prestashop/'; var static_token = '440a98dc7f29b71e391b2a7aeb0621ff'; var token = 'fffc8556fea84997399b555738cfc40a'; var priceDisplayPrecision = 2; var roundMode = 2; [removed] [removed][removed] [removed][removed] [removed][removed] <!-- Block search module HEADER --> <link rel="stylesheet" type="text/css" href="http://localhost/prestashop/css/jquery.autocomplete.css" /> [removed][removed] <!-- Block search module HEADER --><link rel="alternate" type="application/rss+xml" title="MCO Store" href="http://localhost/prestashop/modules/feeder/rss.php?id_category=0&orderby=position&orderway=ASC" /> </head> No link rel there of the one its supposed to add. Link to comment Share on other sites More sharing options...
Truemedia Posted September 25, 2010 Author Share Posted September 25, 2010 Never mind works after position shift, now I'm go try something new . Link to comment Share on other sites More sharing options...
Truemedia Posted September 26, 2010 Author Share Posted September 26, 2010 Iv'e got a lot of things working such as automatic size adjustment before smarty and the if statements working in the tpl, but it seems to be actually sending out my links backwards.Should be link1, link2, link3 ectBut instead it's link3, link2, link1This is probably cause of how smarty is working needs to go backwards through the array, but is there a way of reversing this code to show the links in the right order? {foreach from=$blocklink_links item=blocklink_link name=loop} {if $smarty.foreach.loop.first} {$blocklink_link.$lang} {elseif $smarty.foreach.loop.last} {$blocklink_link.$lang} {else} {$blocklink_link.$lang} {/if} {/foreach} Thanks Link to comment Share on other sites More sharing options...
rocky Posted September 27, 2010 Share Posted September 27, 2010 That code should be displaying them in the same order they are in the array. Are you sure they aren't backwards in the array? You can use the following in the PHP file to reverse the elements: $blocklink_links = array_reverse($blocklink_links); Link to comment Share on other sites More sharing options...
Truemedia Posted September 27, 2010 Author Share Posted September 27, 2010 Yeh that worked , not sure why I didn't think of that before thanks. Link to comment Share on other sites More sharing options...
MrBaseball34 Posted September 27, 2010 Share Posted September 27, 2010 Get them from the database in the correct order, perhaps? Link to comment Share on other sites More sharing options...
mir-aus Posted May 18, 2011 Share Posted May 18, 2011 I have same problem in this website,can you help me where should I add:$blocklink_links = array_reverse($blocklink_links);to fix the error ?the link is:http://marbleceramiccorp.com.au/content/11-photo-gallery Link to comment Share on other sites More sharing options...
Rimming Josh Posted June 28, 2019 Share Posted June 28, 2019 I have some problem in my website ( Sydney Stone Polishing ), can anyone help me? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now