mimpro Posted August 5, 2013 Share Posted August 5, 2013 (edited) Hi buddies. PRESTASHOP V 1.5.4.1 - Chrome I am really need a guide here. the problem is simple. I made a custom module with form interface for admin. And in the form, i need to put an iframe. So i tweaked the form.tpl and managed to place an iframe element there. the source is homepage address, which i call from smarty {$base_url}. <iframe src="{$base_url}"></iframe> and the result, iframe element is there but nothing appeared in it. Using google inspect element, i found that the src attribute has nothing. Means the smarty {$base_url}.isn't recognized in the form.tpl. Anything i missed? I thought smarty variables are global properties that can use anywhere? it seems that the admin section might have some tricks here. Anybody please give a hint.. Edited August 19, 2013 by PascalVG (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted August 5, 2013 Share Posted August 5, 2013 if you use {debug} does this variable appear on the variables list (in popup window with debug informations) 1 Link to comment Share on other sites More sharing options...
mimpro Posted August 5, 2013 Author Share Posted August 5, 2013 (edited) it's there $base_url Smarty_Variable Object (3) ->value = "http://localhost:2121/prestashop/newt..." ->nocache = false ->scope = "Smarty root" what's next? Edited August 5, 2013 by mimpro (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted August 5, 2013 Share Posted August 5, 2013 omg that's strange, so if there is variable it should appear in the template file :/ maybe it's related to the cache? if you use {$base_url} outside the iframe, it appear? Link to comment Share on other sites More sharing options...
mimpro Posted August 5, 2013 Author Share Posted August 5, 2013 (edited) well i don't know where to put else the {$base_url} outside the iframe.. but if i replace the {$base_url} with a url (full written), the iframe works. but i really need {$base_url} to work, rather than write urls. coz for multishop features, the result would differ.. Edited August 5, 2013 by mimpro (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted August 5, 2013 Share Posted August 5, 2013 just put this variable somewhere else, anywhere you want, just not in the src="" param. this is for test purposes only. Link to comment Share on other sites More sharing options...
mimpro Posted August 5, 2013 Author Share Posted August 5, 2013 i added as 'alt' <iframe src="{$base_url}" alt="{$base_url}"></iframe> page result: <iframe src="" alt=""> Link to comment Share on other sites More sharing options...
Nils-H Posted August 9, 2013 Share Posted August 9, 2013 Did you call your variable '$base_url' or 'base_url' when creating the assignment array? In your php file, you assign the variable name without the '$'. In the template, you reference it with the '$'. 1 Link to comment Share on other sites More sharing options...
mimpro Posted August 10, 2013 Author Share Posted August 10, 2013 Nils-H, thank you for the tip. I would like to try it both. Previously, the first attempt was calling {$base_url} from the template (form.tpl). It doesn't work. Then I tried calling {$base_url} from php file. Same results. So based on your tip, thing left to try is calling {base_url} as you mentioned, without the $. But I am on festival celebration here, after this i'll get back to code and share the results. Cheers! ps: is there any reason why have to exclude '$' when calling variable from php file? Link to comment Share on other sites More sharing options...
Nils-H Posted August 10, 2013 Share Posted August 10, 2013 What I meant was, in your php you do: $this->context->smarty->assign(array('base_url' => 'http://etc...')); Then in your tpl you refer to it with {$base_url} Link to comment Share on other sites More sharing options...
mimpro Posted August 19, 2013 Author Share Posted August 19, 2013 (edited) Hi.. Actually i didn't try it $this->context->smarty->assign(array('base_url' => 'http://etc...')); this is because my main objective is to call the base url automatically since it is a smarty variable. The suggested above which has 'http://etc...' that it seems the value has to set manually. The concept is, from back office admin, i want user to see 'preview' of the web instantly. Normally, from backoffice, you need to open your front office separately in other browser tab. This is problematic sometimes if you want to track your changes made, which you have to work with two browser tabs at a time. and, actually both front office and back office is all your own url. So no need to put manually url since it is all from the web root. That is why i tried the smarty {$base_url} variable. This should be an advantage because of Smarty do the works for you. So each of the user who use this module that i made, will get : 1. automatic web preview to their front office layout, from admin panel (without required to change the url value manually) 2. for multishops, the smarty generates the exact shop for user preview, based on the active shop chosen in admin mode. ----- The good news is.. i found a SOLUTION! ----- Well, I am new to coding. But it encourages me to explore more to gain knowledges, tips and tricks. Thank you for your suggestions here. Since I got a solution I would like to share it here, and benefits to people who requires this method in their development. Since the objective here is using smarty variable {$base_url} but from back office template file --> form.tpl the attempt was unsuccessful. Then I tried to call the value {$base_url} from the my_module.php also unsuccesfull. I tried to look for the original code which prestashop links to 'view my shop' indeed it doesn't call the url using {$base_url}. Well further research i found that {$base_url} only used in front office templates. The effective way actually is by using this code: 'your_variable_name' => $this->context->shop->getBaseURL(); which 'your_variable_name' will have return the right value of the url itself, even if it is in multishop mode and this value sends to form.tpl and you'll get the output as you wish. while i don't know why this is working for my case, but it is based on the original Prestashop core code. This is not an official solution here. Just try and error method, and if this would be simplified more, please share together.. Well thank you for listeners here. I am happy now. PS: please mark this post as solved. Edited August 19, 2013 by mimpro (see edit history) Link to comment Share on other sites More sharing options...
PascalVG Posted August 19, 2013 Share Posted August 19, 2013 Hi mimpro, Thanks for the feedback. One more thing you could have tried, to use this: __PS_BASE_URI__ instead of the {$base_dir}. This might have worked as well (It contains, as you guessed, the base URL. $base_url gets it's value from this one. I'll mark it as solved, pascal 1 Link to comment Share on other sites More sharing options...
vekia Posted August 19, 2013 Share Posted August 19, 2013 Hello pascal, and what about ssl if i will run store with ssl certificate, then __PS_BASE_URI__ returns https:// just wondering, i never tested it Link to comment Share on other sites More sharing options...
PascalVG Posted August 19, 2013 Share Posted August 19, 2013 Hi Vekia, The definition is as follows: (config/config.inc.php) define('__PS_BASE_URI__', $context->shop->getBaseURI()); function getBaseURI() is coded as follows: (classes/shop/ShopUrl.php) public function getBaseURI() { return $this->physical_uri.$this->virtual_uri; } Where physical_uri and virtual_uri are defined in the ps_shop table: (classes/shop/Shop.php) $this->physical_uri = $row['physical_uri']; $this->virtual_uri = $row['virtual_uri']; So it's not dependent on any ssl setting or not, it seems to only give the relative path from the shop root. My 2 cents, pascal 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