Getting & Giving Support
- Ref. - PHPDoc
Wolf CMS books section
find() function can be used to find and retrieve Page objects. As such, it needs a value to search on, either a “slug” value or a variable. It returns a Page object which has further functions to retrieve page information (or an array of information, depending on which of the object's function you use). A simple example:
<?php $pageobject = $this->find('/about-us'); echo $pageobject->link(); ?>
You can also directly access the object's (in this case)
link() function with a short hand notation. This prevents you from first having to assign the result of the
find() function to a variable before accessing the object's functions. A simple example:
<?php echo $this->find('/about-us')->link(); ?>
These two examples are functionally the same and produce the following HTML from anywhere in the site:
<a href="http://www.mywolfsite.com/about_us">About us</a>
For the “main” level of navigation,
find() does not need forward-slashes. All of these will produce the same result:
find() can be used in conjunction with most (probably all!) of Wolf's other functions, not just “link”, as in the example above.
See also the entry for the findById() function.
When looking for child-of-child pages1), both terms need to be given:
- “hard” set:
- using variables:
Note that the getUri() function gives all slugs for a page, including the slugs of all ancestor pages.
The value of the search term can be contained in a variable. For example, the conditional navigation in the “Wolf” default layout finds a variable,
$parent, which is the current top-level navigation page. Using this value in conjunction with the "children" function produces a dynamic listing of child-pages, giving a simple menu:
<?php // simplified code: $topPage = $this->find($parent); ?> <ul> <?php foreach ($topPage->children() as $subPage) : ?> <li><?php echo $subPage->link(); ?></li> <?php endforeach; ?> </ul>