Jump to content

Get URL of current page


Recommended Posts

I tried to find out how I could get the URL of the current page into my .tpl-file.
Finally found a way, PHP variables through Smarty:
{$smarty.server.HTTP_HOST}{$smarty.server.REQUEST_URI}

This could for example be used to put a Facebook like button on the products.tpl that enables the user to like a specific item:

<iframe src="http://www.facebook.com/plugins/like.php?href={$smarty.server.HTTP_HOST}{$smarty.server.REQUEST_URI}&layout=button_count&show_faces=true&width=450&action=like&colorscheme=light&height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:21px;" allowTransparency="true"></iframe>

Do you know of a better way? Please let me know :)

/Mats

  • Like 10
Link to comment
Share on other sites

  • 6 months later...
  • 2 months later...
  • 1 month later...
  • 1 month later...
  • 3 months later...

You can use this on your menu to know in where category/product you are. Anyway, it's recommended to activate friendly URLS.

 

This applies the "Current" CSS style to that special button.

 

<li class="{if {$smarty.server.REQUEST_URI} == 'category.php?id_category=31'}current{/if}">

 

Good luck!

  • Like 1
Link to comment
Share on other sites

  • 2 months later...

Thats very close to what I want to do.

 

I want to add an anchor link on the page but I want the link to be dynamic based on the URL of the current page.

e.g. If the current url is http://www.mydomain.com/en/widget.html then add a link to the English "Contact Us" page.

If the current url is http://www.mydomain.com/jp/widget.html then add a link to the Japanese "Contact Us" page.

 

What would be even cooler is if there is a Smarty variable that detects the language setting of the current page.

 

Is there a Smarty Variable for that too?

Link to comment
Share on other sites

  • 3 months later...
  • 5 months later...
  • 6 months later...
  • 5 months later...
  • 3 months later...

Hi, that's an interesting thread.

 

I am trying to change width of columns to get a larger column at some pages like the checkout process . ( still using PS 1.4)

 

I already modified the header.tpl  shown below to include and IF condition with  a custom larger  id="center_column_large" which I included in the global.css

{if  ($page_name == 'order' ) || ($page_name == 'order-confirmation' ) || ($page_name == 'authentication' )}
 <div id="custom_large_center_column" class="center_column">
 {else}        
 <div id="center_column" class="center_column">
  {/if}

Everything works perfect with the page specified above but it seems to work only with basic page name located at the root of prestashop. I am not able to add other transaction pages of some payments modules like $page_name == '/modules/bankwire/payment.php' located in deeper subdirectories.

 

I tried $page_name == 'modules/bankwire/payment'  and  $page_name == 'payment' and also $page_name == 'payment.php' no way I can get such page recognized in the IF condition above.
 

I am very close and don't seem so difficult, am I missing something?

Thanks

Link to comment
Share on other sites

 

 

$page_name == 'modules/bankwire/payment'

modules/bankwire/payment is not a page name :)

 

in payment.php file located in bankwire directory (controllers/front subdirectory) add 

public $php_self = 'bankwire';

 

then you will be able to use $page-name == 'bankwire'

Link to comment
Share on other sites

Thanks, it seems a great solution but I am afraid it works only with PS 1.5

 

In  PS1.4 the payment.php of the bankwire module  is located at  .../modules/bankwire/payment.php and  not under controllers.

I tried anyway to add  public $php_self = 'bankwire' to the payment.php anyway that give unexpected error.

 

Any idea how to get same result on PS1.4?

 

Thanks!

Link to comment
Share on other sites

Thanks, it seems a great solution but I am afraid it works only with PS 1.5

 

In  PS1.4 the payment.php of the bankwire module  is located at  .../modules/bankwire/payment.php and  not under controllers.

I tried anyway to add  public $php_self = 'bankwire' to the payment.php anyway that give unexpected error.

 

Any idea how to get same result on PS1.4?

 

Thanks!

 

yes, unfortunately in prestashop 1.4 it will not work.

you can use condition like:

 

{assign var="url" value=$smarty.server.HTTP_HOST$smarty.server.REQUEST_URI}

{if $url=="http://yourwebsite.com/modules/bankwire/payment.php}

do something

{/if}

{if 

  • Like 1
Link to comment
Share on other sites

  • 2 months later...

For those who searches this forum from search engines. The solution is to use global smarty variable in PrestaShop {$request} instead of {$smarty.server.HTTP_HOST}{$smarty.server.REQUEST_URI}.

Works in PS.16, did not check if available on PS1.5

Link to comment
Share on other sites

  • 1 month later...

For those who searches this forum from search engines. The solution is to use global smarty variable in PrestaShop {$request} instead of {$smarty.server.HTTP_HOST}{$smarty.server.REQUEST_URI}.

 

Works in PS.16, did not check if available on PS1.5

 

it returns also variables defined in $_GET ?

Link to comment
Share on other sites

  • 6 months later...

Hi, 

I have multishop so i need to check which shop is currently being used to determine which copyright text to display. Can anyone help?

 

this is the code from block cms

<div>
Copyright © i.net.au 1997-2015
</div>
 
if url = i.net.au 
than
Copyright © i.net.au 1997-2015
else 
Copyright &copy pcm.com.au 1997-2015
 
Can anyone help ??
Link to comment
Share on other sites

  • 1 month later...
  • 1 year later...

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...