While programming, you can request the content of a certain section by URL, with something like http://www.example.com/section-nickname/content-nickname. The requested content is loaded into the $section["currentContent"]
array, while more content – actually every content in the same section – is placed into the $section["childContents"]
array. This additional content is loaded in "base level mode" (cfr. the API manual, "baseLevel"), which means that only basic informations about various objects are given (such as the title, the description, its ID and a few more).
Now this is indeed useful in standard scenarios: when you are showing a particular content and listing, at the same time, related contents in the same section. Imagine you are showing an article and you want to put links to more contents in a contextual menu. This is common, but sometimes you are interested only in a single object, while you don't really need to load all related stuff.
In these cases you can improve the data loading performance by excluding this additional content (you actually give up the option of having also $section["childContents"]
array). Obviously the improvement will be much more evident when that particular section is burdened, it has got many objects inside.
However, moving forward into the discussion started in the previous article "Customizing Frontend Applications [part 1]: divide objects by type in a section", we're going to use the Frontend Controller attribute $sectionOptions
. This time too, we may proceed in two different ways, the choice depending on whether we want a custom behavior for a specific section (1) or alternatively we prefer to modify the default behavior for the whole frontend application (2).
So I'm showing you both:
1. Custom behavior for a section
Like we did in the previous post, we are going to use the nicknameBeforeFilter callback: It is automatically called before section data are loaded, so in the controller:
protected function section-nicknameBeforeFilter() { $this->sectionOptions["showAllContents"] = false; }
(pay attention to change "section-nickname" with the exact nickname of your section).
2. Change the default behavior
To change the way the API answers to requests, edit your Pages Controller. You have to change the $sectionOptions
attribute, by setting the showAllContents property to false:
protected $sectionOptions = array( "showAllContents" => false, "itemsByType" => false, "childrenParams" => array() );
When showAllContents is set to false, we say to the API not to load all related content when a specific content is requested.