Главная страница


ru.perl

 
 - RU.PERL ----------------------------------------------------------------------
 From : Oleg Bakiev                          2:5020/400     10 Apr 2001  16:29:51
 To : All
 Subject : Hа: Шаблоны
 -------------------------------------------------------------------------------- 
 
 
 "Sergey Kantarovich" <sercons@012.net.il> сообщил/сообщила в новостях
 следующее: news:9aun8c$25e$1@host.talk.ru...
 
 >
 > Может кто подскажет как сделать такую вещь:
 > В текстовом файле хранится html шаблон из которого потом генерится
 > страничка. Задача: нужно что бы подпрограмма пробегала по файлу, находила
 > спецтеги %% СПЕЦТЕГ %% , заменяла их на значения локальных переменных и
 > отдавала уже обработанный текст основной программе.
 > Hапример:
 > <html><body><title> %%$title%%</title>
 > После выполнения подпрограммы должно стоять значение переменной $title
 >
 
 Очередное изобретение велосипеда.
 Помедитируй над текстом:
 "When people make a template module like this one, they almost always start
 by inventing a special syntax for substitutions. For example, they build it
 so that a string like %%VAR%% is replaced with the value of $VAR. Then they
 realize the need extra formatting, so they put in some special syntax for
 formatting. Then they need a loop, so they invent a loop syntax. Pretty soon
 they have a new little template language.
 
 This approach has two problems: First, their little language is crippled. If
 you need to do something the author hasn't thought of, you lose. Second: Who
 wants to learn another language? You already know Perl, so why not use it?
 
 Text::Template templates are programmed in Perl. You embed Perl code in your
 template, with { at the beginning and } at the end. If you want a variable
 interpolated, you write it the way you would in Perl. If you need to make a
 loop, you can use any of the Perl loop constructions. All the Perl built-in
 functions are available. "
 --- ifmail v.2.15dev5
  * Origin: AAA Intersvyaz (2:5020/400)
 
 

Вернуться к списку тем, сортированных по: возрастание даты  уменьшение даты  тема  автор 

 Тема:    Автор:    Дата:  
 Шаблоны   Sergey Kantarovich   10 Apr 2001 14:29:37 
 Hа: Шаблоны   Oleg Bakiev   10 Apr 2001 16:29:51 
Архивное /ru.perl/648953387f50.html, оценка 1 из 5, голосов 10
Яндекс.Метрика
Valid HTML 4.01 Transitional