Ilya Hoilik Posted October 1, 2017 Posted October 1, 2017 Hello! What's a reason to convert \IPS\Helpers\Table to a string? In some places I see something like this: \IPS\Output::i()->output = (string) $table; /* or */ \IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'group' )->template( (string) $table ); Can you please avoid converting to a string? It will allow us to hook into a method and change something in the table without touching original code. So, for example, let's test this code: When you convert $table to a string we can do nothing with it: When you don't convert it, then we can easy change something we need: In the second case we stay original code untouched, that is better than replacing a whole method.
CodingJungle Posted October 2, 2017 Posted October 2, 2017 in your second example: \IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'group' )->template( (string) $table ); printing/echoing of \IPS\Output::i()->output will return a string any way, even if $table wasn't being casted to a string, cause the template would've done that if they did {$table|raw} inside the template. however your first one, i could see there isn't a need to cast to string. however, i would ask, is there no other way to hook into what you need, before that point?
bfarber Posted October 3, 2017 Posted October 3, 2017 What are you trying to accomplish exactly? Typically we want the data as a string, which is why we cast it.
Ilya Hoilik Posted October 3, 2017 Author Posted October 3, 2017 Add a new filter option and new fields to the advanced search 13 hours ago, CodingJungle said: cause the template would've done that if they did {$table|raw} inside the template But we can hook into that template and change $table in the template's PHP method
Ilya Hoilik Posted October 3, 2017 Author Posted October 3, 2017 13 hours ago, CodingJungle said: however, i would ask, is there no other way to hook into what you need, before that point I'm not actually sure, but I think there's not.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.