[solved]Filter pagelist by custom attribute (conditional)
Permalink
Hi,
I am trying to filter a specific pagelist template by a custom attribute.
If i ad the filterByAttribute function to the pagelist (custom) controller:
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?
PS Hardcoding a pagelist in the page template is not an option....
Thanks,
Sacha
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....
Thanks,
Sacha
i am not sure if i get you, but you can obtain block template(file) name used for rendering with this code:
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....
many thanks!
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!