Forum
cannot read page argument in addon code
Here is debug code that show up when page loads
Matched route: [lang:lang]/brand/about
Using master page: /templates/pages/about.php
Page arguments:
Array
(
[0] => /de/brand/about
[lang] => de
[1] => de
)
I have an add-on that needs to read [lang] variable, but I can't seem to read it.
I have tried using perch_get('lang'), but does not work. I don't know what else to try.
route pattern in db looks like below
routePattern: [lang:lang]/brand/about
routeRegExp: ^/(?<lang>[a-z]{2})/brand/about/?$
perch_get('lang') is the proper way to retrieve that data from the URL
You can see that lang is in the page arguments, so you will need to debug your PHP in the usual way.
I was not getting variables via perch_get('lang').
finally, I got it working using below code
thought it may help others
I wouldn't advise anyone else to do that. You're running the router twice, using private API methods, and we can't guarantee that the behaviour you're currently getting will persist.
Drew, what would you advice I use. perch_get() is not working for sure.
I found this by debugging the usual PHP way.
We would advise you use
perch_get
and figure out why it isn't working in your scenario. We can't support the method you are using.