Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend Framework: when to use placeholders, partials, and just plain assigning to view properties?

I've been reading through the Zend_View documentation, and I'm not quite sure I understand exactly when it's best to use placeholders, partials, and just using view properties. Here's my basic understanding:

Placeholders: use mostly when aggregating content, i.e. sidebar sections.

Partials: use when you want the view script to be rendered without the view's variable scope. But when are the times that this would be optimal?

View properties: any other variables you need to pass to the view script that don't fit into the above.

like image 824
blacktie24 Avatar asked Mar 20 '11 23:03

blacktie24


People also ask

What is the use of property placeholder in spring?

Spring context:property-placeholder The context:property-placeholder tag is used to externalize properties in a separate file. It automatically configures PropertyPlaceholderConfigurer, which replaces the $ {} placeholders, which are resolved against a specified properties file (as a Spring resource location).

What is the propertysourcesplaceholderconfigurer?

Working with the PropertySourcesPlaceholderConfigurer gives us full control over the configuration, with the downside of being more verbose and most of the time, unnecessary. Let's see how we can define this bean using Java configuration:

How to declare partial view in ASP NET Core?

Declare partial views. A partial view is a .cshtml markup file without an @page directive maintained within the Views folder (MVC) or Pages folder (Razor Pages). In ASP.NET Core MVC, a controller's ViewResult is capable of returning either a view or a partial view. In Razor Pages, a PageModel can return a partial view represented as ...

How are partial views referenced by name?

When a partial view is referenced by name without a file extension, the following locations are searched in the stated order: The following conventions apply to partial view discovery: Different partial views with the same file name are allowed when the partial views are in different folders.


1 Answers

Placeholders

As you mentioned, these are good for aggregating content. The most common task is to collect data from views and display the entire collection in your layout.

For example, say you know that every page requires jQuery. Your layout would then have something like this using the inlineScript placeholder helper

<?php echo $this->inlineScript()->prependFile('path/to/jquery.min.js') ?>
</body>

You views can then add scripts to the placeholder, eg

<?php $this->inlineScript()->appendFile('path/to/script.js') ?>

Partials

A view partial is a way to encapsulate data rendering. Particularly useful if you want to use the same markup in more that one place.

For example, say you show the same table format where only the data changes (think pagination). A view partial is perfect for this.

View Properties

Your controllers should assign properties to the view based on the specific task at hand. These properties are usually your models / collections of models or forms (when using Zend_Form), whatever your particular view needs to display.

like image 87
Phil Avatar answered Sep 29 '22 11:09

Phil