Prev | Current Page 541 | Next

W. Jason Gilmore

"Beginning PHP and MySQL: From Novice to Professional"


Furthermore, because the presentational logic used by most templating
engines is typically more simplistic than the syntax of whatever programming
language is being used for the application, the designer is not required to undergo
a crash course in that language in order to perform their job.
But how exactly does a templating engine accomplish this separation? Interestingly,
most implementations offer a well-defined custom language syntax for carrying
out various tasks pertinent to the interface. This presentational language is embedded in
a series of templates, each of which contains the presentational aspects of the application
and would be used to format and output the data provided by the application??™s logical
component. A well-defined delimiter signals the location in which the provided data
and presentational logic is to be placed within the template. A generalized example of
such a template is offered in Listing 19-1. This example is based on the templating engine
Smarty??™s syntax. However, all popular templating engines follow a similar structure, so if
you??™ve already chosen another solution, chances are you??™ll still find this chapter useful.
Listing 19-1. A Typical Template (index.tpl)


{$pagetitle}

CHAPTER 19 ?–  TEMPLAT ING WITH SMARTY 473

{if $name eq "Kirk"}

Welcome back Captain!


{else}

Swab the decks, mate!


{/if}


There are some important items of note regarding this example.


Pages:
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553