Jump to content

renderNav to output more than one field


Recommended Posts

Assume I'm using the site-default template from the current 2.5.2 release/

In my page, I have fields "summary", "duration" and "instrument"

I'm using this in my template:

if($page->hasChildren) $content .= renderNav($page->children, 0, 'summary && duration && intrument');

Is that the correct way? I mean, using those && operators? It seems to work, but I just want to make sure it's the best and most efficient way. I may end up wanting to output about 10 fields and don't want it to slow things up.

Link to comment
Share on other sites

A look at the code of the function renderNav shows that several field names are expected to be separated by blanks:

function renderNav($items, $maxDepth = 0, $fieldNames = '', $class = 'nav') {
    // .....................
	if($fieldNames) foreach(explode(' ', $fieldNames) as $fieldName) {
    // .....................

  • Like 2
Link to comment
Share on other sites

Got it. That makes sense now.

Here's another sort of related question.

So, this nav will output the title of a page, and any the title of any extra field. That's great.

Now, what if one of those fields is a repeater field. And what if I want to display each item within the repeater field? I set up this...

        foreach($item->my_repeater_field as $foo) {
            foreach($foo->my_multi_page_field as $bar) {
                $out .= $bar->get('my_field');

And it renders perfectly, as expected, but when I use it in conjunction with the nav function, it throws the following error...

Warning: Invalid argument supplied for foreach()

It's strange, because it actually works and outputs and loops through the fields as expected. Any clues?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...