XF 2.2 Getting part of a URL in a template?

grantus

Active member
I have a custom page which is something like this: http://www.example.com/mysection/test/?cat=mycat&battle=182

I'm trying to set a custom page title inside my node template HTML.

So far I've tried substr which works, but since the battle=182 part is dynamic, it's not ideal.

I would like to use explode or strpos but those aren't available in Xenforo.

How can accomplish this?
 

briansol

Well-known member
it should be available within the parameterbag.

if you have a lot of options, you can iterate through it or just define a few locals that take in the parameterbag in the filter.

Code:
class YourClass extends AbstractController
{    
	public function actionIndex(ParameterBag $params)
	{

                $battle = $this->filter('battle', 'str');
                $somethingelse = $this->filter('somethingelse', 'str');

                if($battle){
                         //handle it
                }
               if($somethingelse){
                       //handle it
               }
         }
}
 

grantus

Active member
it should be available within the parameterbag.

if you have a lot of options, you can iterate through it or just define a few locals that take in the parameterbag in the filter.

Code:
class YourClass extends AbstractController
{   
    public function actionIndex(ParameterBag $params)
    {

                $battle = $this->filter('battle', 'str');
                $somethingelse = $this->filter('somethingelse', 'str');

                if($battle){
                         //handle it
                }
               if($somethingelse){
                       //handle it
               }
         }
}
That's the thing though, I'm just trying to do it within the template, not in an addon.
 

Brogan

XenForo moderator
Staff member
How is the URL generated?

Are there any vars available to the template related to the URL?
 

grantus

Active member
How is the URL generated?

Are there any vars available to the template related to the URL?
Sorry, I should have explained. I have a custom PHP page that I'm calling inside the template HTML part of the node like this:

<xf:callback class="\path\to\file" method="getHtml"></xf:callback>
 
Top