Light-weight, fast, simple and powerful!
Translations of this page?:


The hasContent() function may be thought of as the conditional counterpart of the content() function.1)

It can take two parameters:

  1. A page-part must given as the first parameter. If it is found, the function returns “true”, otherwise it returns “false”.
  2. Like content(), the hasContent() function can also be inherited by setting the second parameter to “true” (optional); by default this is set to “false”.


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.


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.

1) See the content function entry for fuller explanation.
functions/hascontent.txt · Last modified: 2011-09-12 00:46 (external edit)
Except where otherwise noted, content on this wiki is licensed under the following license:GNU Free Documentation License 1.2
Copyright 2010 / design by yello studio / Wolf CMS Inside