After a few googling, I found that there are some database for sale to match IP and country.
Let’s say I can find the user IP, find his country with the database. Now, how can I hook Kirby to replace some text string in the content before it’s sent to the client?
(I am probably totally on the wrong path here, if it’s the case, please tell me something)
As regards replacing strings, might be helpful to see what it is that needs to be replaced, if it is some strings within one field or whatever. Maybe you can use custom kirbytags that render content based on the country?
I have no idea, where to hook in to achieve this, without touching the templates. To replace the content on a completely rendered page you could probably use output buffering, but that would still mean touching the templates. I suppose using JavaScript is not an option?
Well, I guess sooner or later the smarter minds here will come around with a solution…
Yes, I would prefer to avoid JS.
What do you mean by ‘output buffering’ ?
How can I use the function replace_words_in_germany and $countrycode variable on every pages?
(I tried to make a file in the /plugin folder, but still the variable is not accessible from the template)
The Kirbytext filters would indeed be an option but only if you use Kirbytext. Another option is too modify the way Kirby renders templates. It’s super easy to create your custom Kirby class and overwrite the template method. Basically all you need to do is to create a site.php next to the index.php and in there do something like this:
<?php
class CustomKirby extends Kirby {
public function template(Page $page, $data = array()) {
$template = parent::template($page, $data);
$template = replace_words_in_german($template);
return $template;
}
}
$kirby = kirby('CustomKirby');
Thanks for that @desgnl, I too wonder how the caching would react, especially the file cache.
I know that opcache / apc stores scripts in memory for faster loading and have mine setup to check every two seconds if the script has changed.