Page 1 of 1

parameter

Posted: Mon Jul 13, 2020 1:39 am
by php_BB_Lover
Hi,

Dose phpBB have a native method to add parameter to the existing url?

For example i wanna add mypara=a to the existing url.
But when i use ?mypara=a in <a> Tag it will add it to the end of the url with ?. But i wanna check the url first, if its already a parameter in url, add &mypara=a otherwise add ?mypara=a

Thanks

Re: parameter

Posted: Wed Jul 15, 2020 2:44 am
by Peter77sx
Take a look in functions.php and see how parameters are handled for index.php, ucp.php for example.

Re: parameter

Posted: Wed Jul 15, 2020 5:59 am
by php_BB_Lover
Peter77sx wrote:
Wed Jul 15, 2020 2:44 am
Take a look in functions.php and see how parameters are handled for index.php, ucp.php for example.
Question is for existing url (could be any url), not specific url.

Re: parameter

Posted: Wed Jul 15, 2020 7:17 am
by david63
You could probably use the Twig if function (https://twig.symfony.com/doc/3.x/tags/if.html) in conjunction with the Twig slice function (https://twig.symfony.com/doc/2.x/filters/slice.html)

Re: parameter

Posted: Wed Jul 15, 2020 9:10 am
by php_BB_Lover
david63 wrote:
Wed Jul 15, 2020 7:17 am
You could probably use the Twig if function (https://twig.symfony.com/doc/3.x/tags/if.html) in conjunction with the Twig slice function (https://twig.symfony.com/doc/2.x/filters/slice.html)
But i don't know the url before sending the parameter.
You click on a <a tag to insert a parameter to a url that you are on. But you don't know what url you are on.
I don't know what page it is. Dose it have already parameter in the url or not.

Re: parameter

Posted: Wed Jul 15, 2020 9:24 am
by rxu
Not sure if it is what you're saying about, but there's $user->page array which looks like that:

Code: Select all

  'page_name' => string 'test.php'
  'page_dir' => string ''
  'query_string' => string ''
  'script_path' => string '/phpBB/'
  'root_script_path' => string '/phpBB/'
  'page' => string 'test.php'
  'forum' => int 0
So it's possible to get it on phpBB page and analyze if $user->page['query_string'] contains what you need.

Re: parameter

Posted: Wed Jul 15, 2020 9:29 am
by david63
rxu wrote:
Wed Jul 15, 2020 9:24 am
So it's possible to get it on phpBB page and analyze if $user->page['query_string'] contains what you need.
But the OP is wanting to do it within the <a> tag which I assume means within the template file, which is why I suggested using Twig functions.
php_BB_Lover wrote:
Wed Jul 15, 2020 9:10 am
But i don't know the url before sending the parameter.
But you know the name of the parameter that you want to add so you just test to see if it is present or not

Re: parameter

Posted: Wed Jul 15, 2020 9:47 am
by php_BB_Lover
rxu wrote:
Wed Jul 15, 2020 9:24 am
Not sure if it is what you're saying about, but there's $user->page array which looks like that:

Code: Select all

  'page_name' => string 'test.php'
  'page_dir' => string ''
  'query_string' => string ''
  'script_path' => string '/phpBB/'
  'root_script_path' => string '/phpBB/'
  'page' => string 'test.php'
  'forum' => int 0
So it's possible to get it on phpBB page and analyze if $user->page['query_string'] contains what you need.
Thank you. Now im on the phone. I will test tomorrow and post the result.

Re: parameter

Posted: Wed Jul 15, 2020 9:52 am
by php_BB_Lover
david63 wrote:
Wed Jul 15, 2020 9:29 am
But the OP is wanting to do it within the <a> tag which I assume means within the template file, which is why I suggested using Twig functions.
Correct. Im doing this in the template file.
But you know the name of the parameter that you want to add so you just test to see if it is present or not
No, i know the parameter that i want to insert. But i don't know the url that im on.

Re: parameter

Posted: Wed Jul 15, 2020 10:19 am
by david63
php_BB_Lover wrote:
Wed Jul 15, 2020 9:52 am
But i don't know the url that im on.
Then how are you going to do anything if you do not know what you are working with?

If you were to explain fully what it is that you are trying to do, and where you are trying to do it, then it would be a lot easier than trying to pre-guess what you want

Re: parameter

Posted: Wed Jul 15, 2020 11:19 am
by RMcGirr83
david63 wrote:
Wed Jul 15, 2020 10:19 am
If you were to explain fully what it is that you are trying to do, and where you are trying to do it, then it would be a lot easier than trying to pre-guess what you want
👍👍👍👍👍👍👍👍