[solved]Filter pagelist by custom attribute (conditional)


I am trying to filter a specific pagelist template by a custom attribute.

If i ad the filterByAttribute function to the pagelist (custom) controller:

$pl->filterByAttribute('offer_type', "%".$filter_value."\n%", 'LIKE');

It works like it is supposed to work, the only problem is that it applies to all pagelist blocks. I wish to use the filter only in a custom pagelist (view) template, so i have to build in a condition.

Can anybody give me any pointers how to do this? Is something like this possible?
if (pagelist_template == 'pagelistFilter.php') { $pl->filterByAttribute('offer_type', "%".$filter_value."\n%", 'LIKE'); }

PS Hardcoding a pagelist in the page template is not an option....


View Replies: View Best Answer
shahroq replied on at Permalink Best Answer Reply
i am not sure if i get you, but you can obtain block template(file) name used for rendering with this code:
$filename = Block::getByID($this->bID)->bFilename;
echo $filename;
//Result is file name without extension, e.g. 'blog_index'
smenster replied on at Permalink Reply
Hi shahroq,

Many thanks this did the trick! One small note though, i had to include the ".php" extension in my condition. See code below....

$filename = Block::getByID($this->bID)->bFilename;
         if ( $filename == 'pagelist_custom_template.php' )
               $pl->filterByAttribute('offer_type', "%\attribute_value\n%", 'LIKE'); 

many thanks!