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?
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
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.