Erros de Template
Erros de Template (Depuração Smarty)
Seção intitulada “Erros de Template (Depuração Smarty)”Problemas comuns de template Smarty e técnicas de depuração para temas e módulos do XOOPS.
Fluxograma de Diagnóstico
Seção intitulada “Fluxograma de Diagnóstico”flowchart TD A[Template Error] --> B{Error Visible?} B -->|No| C[Enable Template Debug] B -->|Yes| D[Read Error Message]
C --> E{Type of Error?} E -->|Syntax| F[Check Template Syntax] E -->|Variable| G[Check Variable Assignment] E -->|Plugin| H[Check Smarty Plugin]
D --> I{Parse Error?} I -->|Yes| J[Check Braces Matching] I -->|No| K{Undefined Variable?}
K -->|Yes| L[Check Variable in PHP] K -->|No| M{File Not Found?}
M -->|Yes| N[Check Template Path] M -->|No| O[Clear Cache]
F --> P[Fix Syntax] G --> Q[Verify PHP Code] H --> R[Install Plugin] J --> P L --> Q N --> S[Verify paths] O --> T{Error Resolved?} P --> T Q --> T R --> T S --> T
T -->|No| U[Enable Debug Mode] T -->|Yes| V[Problem Solved] U --> DErros Comuns de Template Smarty
Seção intitulada “Erros Comuns de Template Smarty”pie title Template Error Types "Syntax Errors" : 25 "Undefined Variables" : 25 "Missing Plugins" : 15 "Cache Issues" : 20 "Encoding Problems" : 10 "Path Issues" : 51. Erros de Sintaxe
Seção intitulada “1. Erros de Sintaxe”Sintomas:
- Mensagens “Smarty syntax error”
- Templates não compilam
- Página em branco sem saída
Mensagens de Erro:
Syntax error: unrecognized tag 'myfunction'Unexpected "}" near end of templateProblemas Comuns de Sintaxe
Seção intitulada “Problemas Comuns de Sintaxe”Tag de fechamento faltando:
{* WRONG *}{if $user}User: {$user.name}{* Missing {/if} *}
{* CORRECT *}{if $user}User: {$user.name}{/if}Sintaxe de variável incorreta:
{* WRONG *}{$user->name} {* Use . not -> *}{$array[key]} {* Use quoted keys *}{$func()} {* Can't call functions directly *}
{* CORRECT *}{$user.name}{$array.key}{$array['key']}{$user|@function} {* Use modifiers instead *}Aspas desemparelhadas:
{* WRONG *}{if $name == 'John} {* Mismatched quotes *}{assign var="user' value="John"}
{* CORRECT *}{if $name == 'John'}{assign var="user" value="John"}Soluções:
{* Always balance braces *}{if condition} ...{elseif condition} ...{else} ...{/if}
{* Verify tag format *}{foreach $items as $item} ...{/foreach}
{* Check all variables are defined *}{if isset($variable)} {$variable}{/if}2. Erros de Variável Indefinida
Seção intitulada “2. Erros de Variável Indefinida”Sintomas:
- Avisos “Undefined variable”
- Variável exibe como vazia
- Aviso PHP em log de erro
Mensagens de Erro:
Notice: Undefined variable: myvarSmarty notice: variable "$user" not availableScript de Debug:
<?php// In your template file or PHP code// Create modules/yourmodule/debug_template.php
require_once '../../mainfile.php';
// Get template engine$tpl = new XoopsTpl();
// Check what variables are assignedecho "<h1>Template Variables</h1>";echo "<pre>";print_r($tpl->get_template_vars());echo "</pre>";
// Or dump Smarty objectecho "<h1>Smarty Debug</h1>";echo "<pre>";$tpl->debug_vars();echo "</pre>";?>Corrigir em PHP:
<?php// Ensure variables are assigned before rendering$xoopsTpl = new XoopsTpl();
// WRONG - variable not assigned$xoopsTpl->display('file:templates/page.html');
// CORRECT - assign variables first$user = [ 'name' => 'John', 'email' => 'john@example.com'];$xoopsTpl->assign('user', $user);$xoopsTpl->display('file:templates/page.html');?>3. Problemas de Cache
Seção intitulada “3. Problemas de Cache”Sintomas:
- Mudanças no template não aparecem
- Versão antiga do template exibida
Soluções:
# Clear Smarty cacherm -rf xoops_data/caches/smarty_cache/*rm -rf xoops_data/caches/smarty_compile/*
# Or in admin panelAdmin > System > Maintenance > Clear CacheProcedimento de Depuração Passo a Passo
Seção intitulada “Procedimento de Depuração Passo a Passo”- Ativar exibição de erro PHP em mainfile.php
- Limpar cache Smarty
- Ativar modo debug do XOOPS com
XOOPS_DEBUG_LEVEL = 2 - Verificar sintaxe de template para braces desemparelhadas
- Verificar variáveis atribuídas em PHP antes de renderizar
- Usar {debug} em template para inspecionar variáveis
- Verificar logs de erro PHP para erros adicionais
Documentação Relacionada
Seção intitulada “Documentação Relacionada”- Ativar Modo Debug
- Depuração de Template Smarty
- Tela Branca da Morte
- Erros de Permissão Negada
#xoops #templates #smarty #debugging #troubleshooting