Get Smarty

Smarty Icon

You may use the Smarty logo according to the trademark notice.

Smarty Template Engine Smarty Template Engine

For sponsorship, advertising, news or other inquiries, contact us at:

Check reviews of PHP Web Hosting, compatible with Smarty Templates

Фильтры вывода

Когда шаблон выводится через display() или fetch(), результат может быть пропущен через один или несколько фильтров вывода. Отличие их от постфильтров состоит в том, что постфильтры действуют на уже скомпилированный шаблон, перед его записью на диск, в то время как фильтры вывода обрабатывают шаблон в момент его исполнения.

Фильтры вывода могут быть или зарегистрированы или загружены из папки плагинов с помощью функции load_filter(), или с помощью установки переменной $autoload_filters. Smarty передаёт фильтру результат обработки шаблона в качестве первого аргумента и предполагает, что функция вернёт результат своей работы.

Example 15.4. Использование фильтра вывода


<?php
// код в вашем скрипте
function protect_email($tpl_output, &$smarty)
{
    $tpl_output =
       preg_replace('!(\S+)@([a-zA-Z0-9\.\-]+\.([a-zA-Z]{2,3}|[0-9]{1,3}))!',
                    '$1%40$2', $tpl_output);
    return $tpl_output;
}

// регистрация фильтра вывода
$smarty->register_outputfilter('protect_email'); 
$smarty->display('index.tpl');

// теперь все адреса электронной почты в выводе шаблона будут
// обработаны несложной функцией защиты от спам-ботов
?>

  

См. также register_outpurfilter(), load_filter(), $autoload_filters, постфильтрі и $plugins_dir.

Comments
No comments for this page.
Post a Comment
All comments are moderated. Support questions are ignored, use the forums instead.
Author:
Email: (not shown)
What is 9 plus 13? (Are you human?)

Sponsors [info]

Cheap Website Hosting @hostdone.com
email marketing @ActiveCampaign
broadband deals @BroadbandGenie
Best UK Web Hosting @webhost.uk.net
Reliable UK and US Web Hosting @rshosting.com
Cheap US and UK Web Hosting @infrenion.com
I.T Certification Exams @pass-guaranteed.com
Certification Practice Tests @firsttrycertify.com
Certification Practice Exam Questions @ace-it-certifications.com
Broadband Speed Test @broadbandspeed.co.uk
bulk email software @americaint.com
ASP.NET hosting @aspnethosting.co.uk