Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Mise en cache d'un site multilangue

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: French
View previous topic :: View next topic  
Author Message
sertar
Smarty n00b


Joined: 11 Nov 2008
Posts: 2

PostPosted: Tue Nov 11, 2008 2:20 pm    Post subject: Mise en cache d'un site multilangue Reply with quote

Bonjour,

je souhaite mettre en place un système de cache sur mon site mais je ne vois pas comment.
les textes sont définis par des constantes en php et selon la variable de langue , j'inclus en.php par exemple. je passe les constantes via des smarty assign.
le problème est que l'utilisation des blocks {dynamic} n'est pas envisageable vu que sur tout le tpl il y a des variables qui peuvent changer et pas mal de foreach pour les contenues de DB.


Voila un exemple
le en.php
Code:

<?php
define('REG_TITRE', 'Règlement');
?>



Le php :
Code:

<?php
getlang('reglement/fr.php', 'reglement/en.php');
pg_connect(CONNECT);

include('./includes/form/parseur.php');

$langue = LANGUE;
$chartes = array();
$sql = pg_query("SELECT contenu FROM reglement WHERE langue='$langue'");



while($char = pg_fetch_array($sql) )
{
$charte = array();

$charte['contenu'] = parseur($char['contenu']);
array_push($chartes,$charte);
}

$smarty->assign('LANG_REG_TITRE', REG_TITRE);
$smarty->assign('chartes', $chartes);

pg_close();
?>


Le tpl :
Code:

<h2>{$LANG_REG_TITRE}</h2>
<div class="content" align="center">
   {foreach from=$chartes item=charte}
      {$charte.contenu}
   {/foreach}
</div>


Je souhaiterai donc votre avis sur ce problème.

Cordialement

Sertar
Back to top
View user's profile Send private message
gtraxx
Smarty Regular


Joined: 08 Jan 2008
Posts: 56

PostPosted: Tue Nov 11, 2008 3:41 pm    Post subject: Reply with quote

A part utilisez les blocks dynamique je ne vois pas comment faire
j'ai résolu ce probléme avec l'écriture de block dynamique afin d'éviter de mettre en cache le contenu d'une boucle.
J'ai bcp de foreach et de connection en bsd et franchement pas de prob avec des blocks.
facile avec un plugin :

Code:
<?php
/*
* This plug is used only for smarty and directed by
* Gérits Aurélien for clashdesign.
* It is protected by copyright, and can not under any circumstances be copied, distributed to a third person.
* ClashBlockDynamic
* -------------------------------------------------------------
* File:     function.Block_Dynamic.php
* Type:     function
* Name:     Block_Dynamic
* Purpose:  Block dynamic for caching multinclude tpl
* Authors : Gérits Aurélien
* Examples:
* {Block_Dynamic}
* -------------------------------------------------------------
*/
//Pour que smarty accepte les zones dynamiques, a l'interieur d'un template inclus...
function smarty_Block_Dynamic($param, $content, &$Smarty) {
    return $content;
}
?>

puis ensuite dans php :
Code:
$this->smarty->register_block('dynamic', 'smarty_Block_Dynamic', false);
if (!$this->smarty->is_cached('index.tpl',$this->get_db_results())) {

            //$this->smarty->assign('gbook',$this->db->loadData());
            $this->smarty->assign('results', $this->get_db_results());
         }

Ensuite dans le tpl il suffit de mettre tout vos foreach dans

Code:
{dynamic}{foreach}....{/foreach}{/dynamic}

Vous pouvez même demander a smarty que lorsque get quelque chose tu vide cette partie du cache pour la reconstruire
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: French All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP