Recommend this page to a friend! |
Classes of Saro Carvello | PHP Web MVC Framework | wiki/Dynamic-Content.md | Download |
|
![]() IntroductionThe code described in the previous example shows in the
browser the static web page designed in the file Dynamic ContentPages with dynamic content, have the information contained in the pages that change automatically, generally, the changes are based on the contents of variables, arrays or database. WebMVC handles the dynamic content of web pages firstly by giving it a static representation in the Template. For this purpose WebMVC use two elementary elements:
Then it uses some features provided by the View for transforming the static representation of placeholders and blocks into dynamic content. Understanding PlaceholdersA placeholder is rather than a simple string enclosed with braces, which is located somewhere in the template.
For example to define a placeholder named "UserName" located somewhere in the previous
The static output of a template like this is: As you can guess from the output, we built a static structure that predisposes the dynamically showing of a username. The role of a placeholder is to statically represent a place inside the HTML page where a value will be dynamically shown at run-time by the View. In other terms, a placeholder, at run-time, is bound to a value. > Note that placeholder doesn't invalidate HTML syntax. It doesn't introduce any new tags or pseudo code. It'is a simple > string enclosed in braces. Important: For naming a placeholder you don't must use space or starting the name with a number. We will give you some practical examples on the next page about the dynamic handling of placeholders by using the Template, View, and Controller. Special PlaceHoldersWebMVC provides you with some special types of placeholders you can define at design time rather than assign them a value at runtime. These special types are:
Global placeholders are simply PHP constants in the format,
For example, if you design the placeholder Resource placeholders are designed for handling multi-language translations. We will discuss them on this page in depth Understanding BlocksA block is a generic HTML text encapsulated inside two special HTML comments. A block, like a placeholder, is also
located somewhere in the template. The content of a block can also contain placeholders.
For example we now define a block named "Users" located somewhere in a new template
named
The static output of this template is: <h1>Users list</h1> <table>
As you can guess from the output we built a static structure that predisposes the creation of a user list highlighting, for each user, name, and email. A block has different roles. Statically it just represents a place inside the HTML page where live some text. This text may be characterized by any type of HTML/CSS/JavaScript code, also containing placeholders. At run-time, the View can perform many actions against a block by doing different purposes to its text:
> Note that block doesn't invalidate HTML syntax. It doesn't introduce any new tags. It is text/HTML code enclosed in > HTML comments. Important: For naming a block you don't must use space or starting the name with a number. A block can also contain nested block. See the
The static output is: <h1>Users list</h1> <table>
As you can guess from the output we built a static structure that predisposes the creation of a users list, highlighting, for each user, name, email and more a bulleted list of skills. > By using blocks, placeholders, and the View you will able to implement different types of the dynamism of web pages, > such as data tables, numbered and unnumbered lists, options select, divs repetition, content hiding and much more. We will give you some practical examples on the block page about the dynamic handling of blocks and placeholders. SummaryYou learned that, before beginning to generate dynamic content, WebMVC requires you must give a static representation of it by using Placeholders and Blocks. Whats nextIn the next section, we start to speak how a View can dynamically assign some values to the static content of placeholder |