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


The 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:

    $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="">About us</a>

For the “main” level of navigation, find() does not need forward-slashes. All of these will produce the same result:

  • $this->find('/about-us')
  • $this->find('/about-us/')
  • $this->find('about-us')

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.


"Finding" pages at Level 2

When looking for child-of-child pages1), both terms need to be given:

  • “hard” set: $this->find('fruit/apples');
  • using variables: $this->find($parent.'/'.$subpage);

Note that the getUri() function gives all slugs for a page, including the slugs of all ancestor pages.

Using variables

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);
<?php foreach ($topPage->children() as $subPage) : ?>
    <li><?php echo $subPage->link(); ?></li>
<?php endforeach; ?>
1) That is, pages at level “2”; see the level documentation for explanations of levels in Wolf.
functions/find.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