General
Getting Support
Administration
Design
Wolf Reference
Plugin Development
Core Development
- Design documents
- Working guidelines
- References
Press, Graphics and Translations
Wolf CMS books section
hasContent()
The hasContent() function may be thought of as the conditional counterpart of the content() function.1)
It can take two parameters:
- A page-part must given as the first parameter. If it is found, the function returns “true”, otherwise it returns “false”.
- Like
content(), thehasContent()function can also be inherited by setting the second parameter to “true” (optional); by default this is set to “false”.
Examples
Again, like content(), this function relates to a given object, and so is used like this:
<?php echo $this->hasContent('page-part') ? $this->content('page-part'): ''; ?>
For the page-part to be inherited by all descendant pages, use:
<?php echo $this->hasContent('page-part') ? $this->content('page-part', true): ''; ?>
Version notes
< 0.6.0
In versions up to and including 0.6, the name does not quite match the operation of this function: it does not test to see if “page-part” has any content, and then echoes it if there is some text there. Rather, it checks to see if there is a “page-part”, and then echoes whatever is there.
In other words, this function tests to see if a part exists, and will return “true” even if the part is there with no content at all.
0.7.0+
With the introduction of the partExists function, hasContent() now behaves as expected by the name: it checks to see if the part exists and if that part contains any content.
