Outputting FlashMessenger Messages on the Web Site
Finally, we must output any existing messages to the template. In order for messages to be displayed regardless of where the user is in the site (in other words, so we can use it in other areas aside from managing blog posts), we add the display code to the footer.tpl template, because we will be displaying messages in the right column.
Just like the error containers we created for form errors, we will reuse this message container for similar messages we generate from Ajax requests. To achieve this, we check how many messages there are available to be written. If there are none, we apply the display: none style so the message container does not appear. Later, when we add Ajax functionality, we can simply unhide this element as required. If there is more than one message, we will use an unordered list (<ul>) to output the messages.
Listing 7-31 shows the changes we will make to footer.tpl (in the ./templates directory), which checks the $messages array for any messages to output. Note that if there's only one message, the $messages array contains only one element, so we use $messages.0 in Smarty to access this array element.
Listing 7-31. Outputting Status Messages to the Template (footer.tpl)
<div id="left-container" class="column">
<div id="right-container" class="column"> {if $messages|@count > 0}
Average user rating: 5 stars out of 1 votes
Post a comment