Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Shaarli template cache generator
* Shaarli template cache generator
* This script is used to generate Shaarli's RainTPL cache files for translations.
* See
* Usage:
* 1. Remove all PHP files in <shaarli's directory>/tmp/
* 2. Put this file in your Shaarli root directory
* 3. run it in command line or visit http://<your_shaarli>/generate_templates.php
* 4. Then you can import translation strings in Poedit.
require_once __DIR__ .'/vendor/autoload.php';
require_once __DIR__ .'/inc/rain.tpl.class.php';
require_once __DIR__ .'/application/Utils.php';
use \Shaarli\Config\ConfigManager;
use \Shaarli\Languages;
$conf = new ConfigManager();
new Languages(setlocale(LC_MESSAGES, 0), $conf);
RainTPL::$tpl_dir = $conf->get('resource.raintpl_tpl').'/'.$conf->get('resource.theme').'/'; // template directory
RainTPL::$cache_dir = $conf->get('resource.raintpl_tmp'); // cache directory
$templates = array_map(
function($input) {
return substr(basename($input), 0, strpos(basename($input), '.html'));
glob(__DIR__ .'/'. $conf->get('resource.raintpl_tpl').'/'.$conf->get('resource.theme').'/*.html')
$tpl = new RainTPL();
foreach ($templates as $template) {
@$tpl->draw($template, true);
// dummy functions to avoid fatal errors
function isLoggedIn() {}
function ban_canLogin() {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.