FORUMS CLOSED DUE TO SPAM. YOU STILL CAN ADD POST!

Sub pages

Feed 7 posts, 4 voices

Avatar
125 posts

I would like a new kind of menu, how to generate this code?

<a href="javascript:ajaxpage('?pages-test/mysubpage1.html', 'leftcolumn');">My subpage 1</a>
<a href="javascript:ajaxpage('?pages-test/mysubpage2.html', 'leftcolumn');">My subpage 2</a>

Any idea?

 
Avatar
541 posts

with something like that in your foreach loop:

<a href="javascript:ajaxpage('<?php echo $page->url(); ?>', 'leftcolumn');"><?php echo $page->title(); ?></a>
 
Avatar
125 posts

Thank you Philippe,
I would have prefered something like

<ul>
<?php foreach($this->find('/')->children() as $menu): ?>
  <li><?php echo $menu->link(); ?></li>
<?php endforeach; ?>
</ul>
 
Avatar
11 posts
<ul>
<?php foreach($this->find('/')->children() as $menu): ?>
  <li><?=$menu->link($menu->title,"onclick=\"ajaxpage('/".$menu->url."', 'leftcolumn'); return false;\""); ?></li>
<?php endforeach; ?>
</ul>

This should work.
Also mention that in this example links stay work even if javascript is turned off in browser.

 
Avatar
125 posts

thank’s stas!

 
Avatar
11 posts

A better method (graceful degration) would be to have the common foreach loop:

<ul>
<?php foreach($this->find('/')->children() as $menu): ?>
  <li><?php echo $menu->link(); ?></li>
<?php endforeach; ?>
</ul>

and then later add a javascript click()-event all links.
When a user does not have JS enabled, he can navigate anyway.

By the way: See my plugin for only loading the page content via ajax instead of the whole page.

 
Avatar
11 posts

Samuel, you’re right it would be gracefully.
But you’ll have little bit more to do :)

 
Avatar
11 posts

Yep, but only a really little bit with jQuery:

$('a').click(function(){
  ajaxpage($(this).attr('href'), 'leftcolumn');
});