Jump to content

Get current page name or current urls in my module


sphway
 Share

Recommended Posts

I create a simple module and try to get

current page name(like: women-cloth)

 or

current page url (like: www.***.com/en/women),

I use {$page_name} or {$urls.current_url} in .tpl,but doesn't work.

anyone can tell me why? thanks

Share this post


Link to post
Share on other sites

1 hour ago, endriu107 said:

Add to your tpl {debug} you will see all variable you have access.

Thanks for your reply,I debug the {$urls.current_url} and {$page_name},they are all null

e2.jpg

e1.jpg

Share this post


Link to post
Share on other sites

10 hours ago, sphway said:

Thanks for your reply,I debug the {$urls.current_url} and {$page_name},they are all null

 

e2.jpg

e1.jpg

did you try the way as endriu107 suggested, and did you see these variables inside the debug popup ?

Share this post


Link to post
Share on other sites

37 minutes ago, Ress said:

What hook are you using?

i'm using 

displayBackOfficeHeader

displayHeader

displayOrderConfirmation

Share this post


Link to post
Share on other sites

3 hours ago, abdullacm said:

did you try the way as endriu107 suggested, and did you see these variables inside the debug popup ?

I didn't see anything

Share this post


Link to post
Share on other sites

17 minutes ago, sphway said:

I didn't see anything


put {debug} in your tpl file as in the screenshot, then a popup opens with details of all the variables available in the tpl (open as new window, will ask for permission first time)

Screenshot 2022-05-02 at 1.37.00 PM.png

Screenshot 2022-05-02 at 1.37.21 PM.png

Share this post


Link to post
Share on other sites

Maybe your browser didn't allow to show popup...

14 hours ago, sphway said:

Thanks for your reply,I debug the {$urls.current_url} and {$page_name},they are all null

 

{$page_name} is incorrect it should be {$page.page_name}

Share this post


Link to post
Share on other sites

12 minutes ago, abdullacm said:


put {debug} in your tpl file as in the screenshot, then a popup opens with details of all the variables available in the tpl (open as new window, will ask for permission first time)

 

I add {debug} in my tpl file,there is no $urls.current_url and $page_name

Share this post


Link to post
Share on other sites

11 minutes ago, endriu107 said:

Maybe your browser didn't allow to show popup...

 

{$page_name} is incorrect it should be {$page.page_name}

I tried {$page.page_name},still no luck

Share this post


Link to post
Share on other sites

Posted (edited)
20 hours ago, abdullacm said:

try this in your tpl

{Context::getContext()->controller->php_self}

 

I add the code in my php file

$context->smarty->assign(array(
            'all_var' => Context::getContext()
        ));

but no $current_url  and $page_name in the debug popup

Edited by sphway (see edit history)

Share this post


Link to post
Share on other sites

On 5/2/2022 at 4:08 PM, abdullacm said:

try this in your tpl

{Context::getContext()->controller->php_self}

 

did you try this in your tpl file?

Share this post


Link to post
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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More