Autonav + custom page attribute
- I have some pages that have a parent
- Those pages have a "url" custom attribute
- I want to use autonav to display the subpages' "url" attributes.
Basically I have product pages where the manufacturer is advertised and I want to display his URL (which exists as a custom attribute) in a side menu.
I can imagine it being easy but I'm too tired to figure it out. If you help me, PM me your paypal address so I can buy you a beer (and also tell me how much a decent beer costs in your city).
So have a look at creating a Custom Template for the Page List block.
In short: copy view.php from /concrete/blocks/page_list to /blocks/page_list/templates/custom.php. Then to use it, in edit mode, click on a page list block and select Custom Template from the popup menu and select 'Custom' from the drop down. The name of your file in the templates folder, in this case custom.php, is what determines the name of the custom template in the dropdown.
In the page list template, you'll see a for loop that stores a page in $cobj for each iteration. Somewhere in that loop you could simply go:
As an example, here's where I've used this approach to list details from sub-pages:
This page just has a page list block with a custom template that outputs the attributes from each page. It will automatically update when a subpage is added.
The other thing you might be wanting to do is simply outputting an attribute on a particular page type (so hardcoded in a template). If that is the case, you just use:
$c = Page::getCurrentPage(); $website = $c->getAttribute('url');
The example of this using the same site is here:
This is where I have an actual page type 'business' in my theme that that outputs the attributes automatically.
Hope that is the kind of info you are looking for.
I was wondering if AutoNav or PageList could get subpages (recursively) and if there's an "url" custom attribute on a certain page, display it in a menu.
The recursive part is what troubles me.
The default view.php for the Auto-Nav already uses attributes for some behaviour - look at line 56, where is has:
I'm thinking you should be able to retrieve your url attribute the same way and then control the output using it.
I do find the autonav a bit confusing myself, I've only edited a few times for things simpler things like adding specific classes to menu items.
It was developed by jordanlev who seems to be my favorite community member for a while now. With his autonav view.php it was quite easy for me to achieve my goal.
Check it out, it should be included as the default template IMO.
Glad you figured this out. Since you're comfortable working with the template code, I think that's the best solution. But for future reference, I had an idea for a simpler solution -- just add "External Link" pages under each company in the sitemap (the title of the page can be the url as well, if you want that to be displayed in the menu).