How do you implement a new filter?

54 views
Skip to first unread message

Derek Loewen

unread,
Feb 3, 2018, 8:20:13 PM2/3/18
to f3-fra...@googlegroups.com
I read the docs on creating a new filter here: https://fatfreeframework.com/3.6/preview#filter, yet when implementing the sample code mentioned in the example, I get a 500 error pointing to the template render() method (this is with debug level 3). 

The class is autoloading from a /libs/ folder and this line is in my main model constructor: 
\Preview::instance()->filter('badwords','\Helper::instance()->badwords');

Inside the template:

{{ @page.name | badwords }}

I'm running Fat-Free 3.6.3, loaded using composer.

What else should I check?

xfra35

unread,
Feb 5, 2018, 4:13:50 AM2/5/18
to Fat-Free Framework
Please share more information:
  • the contents of the error log
  • the source code of \Helper::instance()->badwords

ikkez

unread,
Feb 5, 2018, 4:43:20 AM2/5/18
to f3-fra...@googlegroups.com
you can also check if your spaces in

{{ @page.name | badwords }}

are really spaces.. especially after | ... because on a mac, when you type | it's alt + 7, but in case you hold alt a second too long, and inadvertently press space + alt, it'll insert a non-breaking space (NBSP, U+00A0) and the template parser breaks on that one, which looks like a normal space, but is not.

Derek Loewen

unread,
Feb 5, 2018, 9:54:13 PM2/5/18
to ikkez via Fat-Free Framework, f3-framework+APn2wQdllyYRCbrJQTu...@googlegroups.com, Fat-Free Framework
@ikkez - I'm on Windows, but tried re-typing just in case - same result.

@xfra35 - this is what shows in the error log. Probably what's most interesting is "Invalid method NULL" - yet the filter should be registered because of calling \Preview::instance()->filter('badwords','\Helper::instance()->badwords'); prior to rendering the template, right?bad
The badwords method is the same as seen in the documentation:
class Helper extends \Prefab {
	function badwords($val) {
		$bad_words = array("badword","jerk","damn");
		$replacement_words = array("@#$@#", "j&*%", "da*@"); 
		return str_ireplace($bad_words, $replacement_words, $val);
	}
}

[06-Feb-2018 02:45:51 UTC] Invalid method NULL
[06-Feb-2018 02:45:51 UTC] [E:/MAMP/htdocs/passhub/vendor/bcosca/fatfree-core/base.php:2190] Base->error()
[06-Feb-2018 02:45:51 UTC] [E:/MAMP/htdocs/passhub/vendor/bcosca/fatfree-core/base.php:1794] user_error()
[06-Feb-2018 02:45:51 UTC] [E:/MAMP/htdocs/passhub/tmp/k38epssxilwc.e50avz1v1w8c.php:13] Base->call()
[06-Feb-2018 02:45:51 UTC] [E:/MAMP/htdocs/passhub/vendor/bcosca/fatfree-core/base.php:2733] require('E:\MAMP\htdocs\passhub\tmp\k38epssxilwc.e50avz1v1w8c.php')
[06-Feb-2018 02:45:51 UTC] [E:/MAMP/htdocs/passhub/vendor/bcosca/fatfree-core/base.php:2976] View->sandbox()
[06-Feb-2018 02:45:51 UTC] [E:/MAMP/htdocs/passhub/tmp/k38epssxilwc.24glerumkqckw.php:83] Preview->render()
[06-Feb-2018 02:45:51 UTC] [E:/MAMP/htdocs/passhub/vendor/bcosca/fatfree-core/base.php:2733] require('E:\MAMP\htdocs\passhub\tmp\k38epssxilwc.24glerumkqckw.php')
[06-Feb-2018 02:45:51 UTC] [E:/MAMP/htdocs/passhub/vendor/bcosca/fatfree-core/base.php:2976] View->sandbox()
[06-Feb-2018 02:45:51 UTC] [E:/MAMP/htdocs/passhub/app/models/PassHub/Logins.php:42] Preview->render()
[06-Feb-2018 02:45:51 UTC] [E:/MAMP/htdocs/passhub/vendor/bcosca/fatfree-core/base.php:1806] PassHub\Logins->view()
[06-Feb-2018 02:45:51 UTC] [E:/MAMP/htdocs/passhub/vendor/bcosca/fatfree-core/base.php:1627] Base->call()
[06-Feb-2018 02:45:51 UTC] [E:/MAMP/htdocs/passhub/index.php:10] Base->run()

Derek Loewen

On Mon, Feb 5, 2018 at 3:43 AM, ikkez via Fat-Free Framework <f3-framework+APn2wQcLLxvM44tXyXU...@googlegroups.com> wrote:
you can also check if your spaces in

{{ @page.name | badwords }}

are really spaces.. especially after | ... because on a mac, when you type | it's alt + 7, but in case you hold alt a second too long, and inadvertally press space + alt, it'll insert a non-breaking space (NBSP, U+00A0) and the template parser breaks on that one, which looks like a normal space, but is not.


Am Sonntag, 4. Februar 2018 02:20:13 UTC+1 schrieb Derek Loewen:
I read the docs on creating a new filter here: https://fatfreeframework.com/3.6/preview#filter, yet when implementing the sample code mentioned in the example, I get a 500 error pointing to the template render() method (this is with debug level 3). 

The class is autoloading from a /libs/ folder and this line is in my main model constructor: 
\Preview::instance()->filter('badwords','\Helper::instance()->badwords');

Inside the template:

{{ @page.name | badwords }}

I'm running Fat-Free 3.6.3, loaded using composer.

What else should I check?

--
-- You've received this message because you are subscribed to the Google Groups group. To post to this group, send an email to f3-fra...@googlegroups.com. To unsubscribe from this group, send an email to f3-framework+unsubscribe@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/f3-framework?hl=en
---
You received this message because you are subscribed to a topic in the Google Groups "Fat-Free Framework" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/f3-framework/pEow9Nvplvo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to f3-framework+unsubscribe@googlegroups.com.
To post to this group, send email to f3-fra...@googlegroups.com.
Visit this group at https://groups.google.com/group/f3-framework.
To view this discussion on the web visit https://groups.google.com/d/msgid/f3-framework/f6e6da11-5a8d-4b47-ab60-185ce8cc77c8%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

xfra35

unread,
Feb 6, 2018, 4:00:23 AM2/6/18
to Fat-Free Framework
If you're using the Template class, you should register filters with this same class:
\Template::instance()->filter('badwords','\Helper::instance()->badwords');
Reply all
Reply to author
Forward
0 new messages