Jump to content

[SOLVED]Smarty variable in form.tpl doesn't work?


mimpro

Recommended Posts

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 by PascalVG (see edit history)
Link to comment
Share on other sites

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 by mimpro (see edit history)
Link to comment
Share on other sites

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

  • 2 weeks later...

Hi..

Actually i didn't try it

$this->context->smarty->assign(array('base_url' => '
'));

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 by mimpro (see edit history)
Link to comment
Share on other sites

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

  • Like 1
Link to comment
Share on other sites

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...