Перейти к содержимому


Smarty-дебаггер в ShopCMS


  • Вы не можете ответить в тему
Сообщений в теме: 4

#1 badisoft

    Продвинутый пользователь

  • Assistent vsupport.club
  • PipPipPip
  • 5075 сообщений
Репутация: 786
Мастер

Отправлено 24 May 2015 - 03:51 PM

Зачем-то он убран.
Я им как-то не пользовался, обходился другими способами, а тут решил попробовать, т.к. обещается видимость в отладчике всех доступных в текущем шаблоне переменных, это было бы удобно.

1. Скачиваем нашу (ну, почти нашу) версию смарти с гитхаба. https://github.com/s...ses/tag/v2.6.28
2. берем оттуда файл debug.tpl и кладем его в core/smarty/
3. в файле indeх.php после строки

$smarty->assign("isadmin", "yes");

вставляем

$smarty->debugging = true;

и получаем при админском доступе отладочную консоль Smarty в отдельном окне.

PS. Если оно не нужно на все страницах, то вместо

$smarty->debugging = true;

вставляем

$smarty->debugging_ctrl="URL";

При таком раскладе консоль будет выводиться только тогда, когда в URL добавлена GET-переменная SMARTY_DEBUG. Например,
http_://yousite.ru/?SMARTY_DEBUG или http_://yousite.ru/bla-bla-bla/?xxx=yy&zzz=ddd&SMARTY_DEBUG
  • 1
http://cpu.badisoft.ru (тестовый сайт), http://badisoft.ru (модули)

#2 Revived

    Продвинутый пользователь

  • Assistent vsupport.club
  • PipPipPip
  • 59 сообщений
Репутация: 0
Начинающий

Отправлено 17 July 2017 - 02:24 PM

А для админки, как сделать?
  • 0

#3 badisoft

    Продвинутый пользователь

  • Assistent vsupport.club
  • PipPipPip
  • 5075 сообщений
Репутация: 786
Мастер

Отправлено 17 July 2017 - 04:17 PM

А для админки, как сделать?

Не пробовал, но должно быть так же. Вставлять надо там, где smarty уже загружен, т.е. в любое место ниже

$smarty = new Smarty;

  • 0
http://cpu.badisoft.ru (тестовый сайт), http://badisoft.ru (модули)

#4 Revived

    Продвинутый пользователь

  • Assistent vsupport.club
  • PipPipPip
  • 59 сообщений
Репутация: 0
Начинающий

Отправлено 17 July 2017 - 11:00 PM

Да, заработало, спасибо.
  • 0

#5 antaNT

    Продвинутый пользователь

  • Download User
  • PipPipPip
  • 33 сообщений
Репутация: 1
Начинающий

Отправлено 17 October 2018 - 07:46 PM

немного переделал :D
{* Smarty *}
{* debug.tpl, last updated version 2.1.0 *}
{assign_debug_info}
{capture assign=debug_output}
<!DOCTYPE html>
<html lang="en">
    <head>
	    <meta charset="utf-8">
	    <meta http-equiv="X-UA-Compatible" content="IE=edge">
	    <meta name="viewport" content="width=device-width, initial-scale=1">
	    <title>Smarty Debug Console</title>
	    <!-- Bootstrap CSS -->
	    {* <link rel="stylesheet" href="/lib/Bootstrap/bootstrap3.3.7_nixcolors/css/bootstrap.min.css"> *}
	    <!-- Latest compiled and minified CSS -->
	    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    </head>
    <body>
<div class="container-fluid">
    <div class="row">
	    <div class="col-lg-12">
		    <div class="page-header text-primary">
			  <h1>ant Smarty Debug Console <small>{$_smarty_debug_output}</small> {$debug_output} </h1>
		    </div>
		    <h2>List of assigned template variables <small class=badge>{$_debug_keys|@count}</small></h2>
		    <div class="cont__ainer" style="margin-top: 20px;">
		    <div class="well" id="list_assigned_vars">
			    {section name=vars loop=$_debug_keys}
				    <span class='label label-primary'>{ldelim}${$_debug_keys[vars]|escape:'html'}{rdelim}&nbsp;<sup>{$_debug_vals[vars]|@count}</sup></span>
			    {sectionelse}
				    <h3><span class='label label-danger'>no template variables assigned</span></h3>
			    {/section}
		    </div>
		    </div>
	    </div>
	    <div class="col-lg-6">
			    <h2>included templates &amp; config files (load time in seconds) <small class=badge>{$_debug_tpls|@count}</small></h2>
			    <ul class="list-group">
			    {section name=templates loop=$_debug_tpls}
			    <li class="list-group-item">    {section name=indent loop=$_debug_tpls[templates].depth}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{/section}
				    <span class={if $_debug_tpls[templates].type eq "template"}text-primary{elseif $_debug_tpls[templates].type eq "insert"}text-info{else}text-default{/if}>
					    {$_debug_tpls[templates].filename|escape:html}</span>
				    {if isset($_debug_tpls[templates].exec_time)}
					    <span class="badge exectime">
					    {$_debug_tpls[templates].exec_time|string_format:"%.5f"}
					    {if %templates.index% eq 0}(total){/if}
					    </span>
				    {/if}
				    </li>
			    {sectionelse}
				    <p>no templates included</p>
			    {/section}
			    </ul>
	    </div>

	    <div class="col-lg-6">
		    <h2>assigned template variables <small class=badge>{$_debug_keys|@count}</small></h2>
		    <div id="table_assigned_vars">
			    {section name=vars loop=$_debug_keys}
					    <div class="text-danger bg-primary" style="border:1px solid lightsteelblue; border-bottom:0; padding:5px 15px;margin-top:10px;"><strong>{ldelim}${$_debug_keys[vars]|escape:'html'}{rdelim}</strong>&nbsp;<sup>{$_debug_vals[vars]|@count}<sup>&nbsp;
					    {if $_debug_vals[vars]|@count >1}<button class="btn btn-xs btn-primary pull-right" type="button" data-toggle="collapse" href="#coll_{$smarty.section.vars.index}"><span class="glyphicon glyphicon-align-justify" aria-hidden="true"></span></button>{/if}</div>
					    <div class="collapse {if $_debug_vals[vars]|@count <=1}in{/if}" id="coll_{$smarty.section.vars.index}" style="border:1px solid lightsteelblue; border-top:0; padding:5px 15px;">{$_debug_vals[vars]|@debug_print_var}</div>
			    {sectionelse}
				    <div>no template variables assigned</div>
			    {/section}
		    </div>
		    <h2>assigned config file variables (outer template scope)</h2>
		    <table class="table table-hover table-condensed" id="table_config_vars">
			    {section name=config_vars loop=$_debug_config_keys}
				    <tr>
					    <td>{ldelim}#{$_debug_config_keys[config_vars]|escape:'html'}#{rdelim}</td>
					    <td>{$_debug_config_vals[config_vars]|@debug_print_var}</td></tr>
			    {sectionelse}
				    <tr><td><p>no config vars assigned</p></td></tr>
			    {/section}
		    </table>
	    </div>
    </div>
</div>


{*		 <!-- jQuery -->
	    <script src="/lib/jquery/1.9.1/jquery.min.js"></script>
	    <!-- Bootstrap JavaScript -->
	    <script src="/lib/Bootstrap/bootstrap3.3.7_nixcolors/js/bootstrap.min.js"></script> *}
	    <!-- Bootstrap core JavaScript
	    ================================================== -->
	    <!-- Placed at the end of the document so the pages load faster -->
	    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
	    <!-- Latest compiled and minified JavaScript -->
	    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
    </body>
</html>
{/capture}
{if isset($_smarty_debug_output) and $_smarty_debug_output eq "html"}
    {$debug_output}
{else}
<script type="text/javascript">
// <![CDATA[
    if ( self.name == '' ) {ldelim}
	   var title = 'Console';
    {rdelim}
    else {ldelim}
	   var title = 'Console_' + self.name;
    {rdelim}
    _smarty_console = window.open("",title.value,"width=1200,height=900,resizable=yes,scrollbars=yes");
    _smarty_console.document.write('{$debug_output|escape:'javascript'}');
    _smarty_console.document.close();
// ]]>
</script>
{/if}

  • 1