We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Plugin parameter returning null :?

Development and Programming

Tyssen's avatar
Tyssen
756 posts
14 years ago
Tyssen's avatar Tyssen

I’m writing a quick plugin to get the page number of paginated entries outside the channel entries look but am having a problem with the variable for $url_segment returning null if the value passed to it uses a segment variable. The plugin code looks like

function Td_page_number()
    {    
        
        $this->EE =& get_instance();
        
        $url_segment = $this->EE->TMPL->fetch_param('url_segment');
        $limit = $this->EE->TMPL->fetch_param('limit');
    
        $segment_number = str_replace("P", "", $url_segment);
        $result = ($segment_number / $limit) + 1;
        
        return $this->return_data = $result;
    }

and the template plugin code is:

{exp:td_page_number url_segment="{segment_2}" limit="3"}

If I change {segment_2} to P3, the plugin returns the result I expect, but if I use {segment_x} it doesn’t and testing $url_segment shows that’s returning null.

Anyone have an idea why?

       
SaucePan Creative's avatar
SaucePan Creative
32 posts
14 years ago
SaucePan Creative's avatar SaucePan Creative

Since parse=”inward” didn’t work and your parameter name is url_segment, why not just use CodeIgniter to get the segment yourself rather than relying on the template parser? So instead of saying url_segment=”{segment_2}” use url_segment=”2”.

Your code would be like so:

$url_segment = (int)$this->EE->TMPL->fetch_param('url_segment');
$url_segment = $this->EE->uri->segment($url_segment);

http://ellislab.com/codeigniter/user-guide/libraries/uri.html

       
Tyssen's avatar
Tyssen
756 posts
14 years ago
Tyssen's avatar Tyssen

:red: You know what? I’m an idiot. The reason I wasn’t getting anything from passing in a segment variable was because I was using a segment that was empty. Now where’s that rock?

       
SaucePan Creative's avatar
SaucePan Creative
32 posts
14 years ago
SaucePan Creative's avatar SaucePan Creative

That makes sense. I have made that mistake before. I was tired last night and couldn’t think of why it wouldn’t parse, I pass template variables in parameters all the time. It’s always some minor oversight.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.