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

Chapter 18. Советы

Обработка пустых переменных

Иногда, например, для того чтобы фон таблицы работал корректно, необходимо вывести вместо пустого значения переменной, значение по умолчанию, например  . Многие бы использовали конструкцию {if} в данной ситуации, но в Smatry есть более короткий путь - используя модификатор переменной default.

Note

PHP выдаст ошибку Undefined variable в случае, если error_reporting() установлен в E_ALL и переменная не была присвоена шаблону Smarty.

Example 18.1. Вывод  , если переменная пуста


{* длинный путь *}
{if $title eq ''}
  
{else}
	{$title}
{/if}


{* короткий путь *}
{$title|default:' '}

   

См. также default и Обработка переменных по умолчанию.

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 5 plus 14? (Are you human?)

Sponsors [info]

Cheap Website Hosting @hostdone.com
Cheap Hosting @HostsVault
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