Skip to content

Instantly share code, notes, and snippets.

@joelmiguelvalente
Created January 7, 2023 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joelmiguelvalente/2c39950195c1c548f1df2554cdb01613 to your computer and use it in GitHub Desktop.
Save joelmiguelvalente/2c39950195c1c548f1df2554cdb01613 to your computer and use it in GitHub Desktop.
Esto es para la versión Smarty 4.3.0
<?php
if(!defined('TS_ROOT')) exit('Nooooo... Vete de aquí!');
/**
* Cargamos la librería de Smarty
*/
require_once TS_INC . "smarty" . DS . "bootstrap.php";
/**
* Inicializamos
*/
$smarty = new Smarty();
/**
* Compilamos los archivos en la carpeta cache
* @link => https://www.smarty.net/docs/en/api.set.compile.dir.tpl
*/
$smarty->setCompileDir(TS_ROOT . "cache");
/**
* Borrar archivos del directorio cache
* @link => https://www.smarty.net/docs/en/api.clear.all.cache.tpl
*/
$smarty->clearAllCache();
/**
* Creamos key para asignarle el valor del directorio,
* ya que estas se usarán en los plugins,
* ex: "key_name" => valor_carpeta
* ======================================
* ATENCIÓN: no deben cambiar ningún valor
*/
$theme = TS_THEMES . TS_TEMA;
$templates = $theme . DS . "templates";
$directorios = [
/**
* Algunas carpetas
*/
"themes" => TS_THEMES,
"avatar" => TS_AVATAR,
"plugins" => TS_UPLOADS,
"covers" => TS_COVERS,
/**
* Tema actual
*/
"tema" => $theme,
"css" => $theme . DS . "css",
"js" => $theme . DS . "js",
"tema_templates" => $templates,
"tema_sections" => $templates . DS . "sections",
"tema_admin" => $templates . DS . "admin_mods" . DS . "admin",
"tema_mods" => $templates . DS . "admin_mods" . DS . "mods"
];
$smarty->setTemplateDir($directorios);
/**
* Indicamos la ruta de los plugins para adicionar al sitio
* @link => https://www.smarty.net/docs/en/api.add.plugins.dir.tpl
*/
$smarty->addPluginsDir(TS_EXTRA . "plugins");
/**
* Con esta función habilitamos el acceso a los directorios agregados
* en la función de $smarty->setTemplateDir(...) si no estan definidos
* no podran obtener el contenido de las mismas v2/v3
* @link https://www.smarty.net/docs/en/advanced.features.tpl#advanced.features.security
* Smarty 4
* @link https://smarty-php.github.io/smarty/programmers/advanced-features/advanced-features-security.html
*/
$smarty->enableSecurity();
/**
* Eliminará: Comentarios, Espacios.
* Basicamente comprimirá todo el html
* @link => https://www.smarty.net/docs/en/api.load.filter.tpl
* @link => https://stackoverflow.com/questions/18673684/minify-html-outputs-in-smarty/28556561
*/
$smarty->loadFilter('output', 'trimwhitespace');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment