MarcC Posted January 15, 2013 Share Posted January 15, 2013 I wanted to run this by the forum, see if anybody can help. I think it may be a concatenation operator problem, which I don't have much experience with. I'm trying to convert the default sitemap.php code to something that outputs into a variable. If I run the following code, I only get a link to "Home" and then a bunch of <!-- this line prints OK -->. Any tips would be appreciated. function sitemapListPage($page) { $siteMap .= "<li><a href='{$page->url}'>{$page->title}</a> "; if($page->numChildren) { $siteMap .= "<ul>"; foreach($page->children as $child) { $siteMap .= "<!-- this line prints OK -->"; sitemapListPage($child); } $siteMap .= "</ul>"; } $siteMap .= "</li>"; return $siteMap; } $outMain .= "<ul class='sitemap'>"; $outMain .= sitemapListPage($pages->get("/")); $outMain .= "</ul>"; Link to comment Share on other sites More sharing options...
Soma Posted January 15, 2013 Share Posted January 15, 2013 Maybe after you got it working you could use the MarkupSimpleNavigation module to do it 1 Link to comment Share on other sites More sharing options...
MarcC Posted January 15, 2013 Author Share Posted January 15, 2013 Good point, Soma. Maybe I'll just do that But I'd still like to know what I'm doing wrong here. Link to comment Share on other sites More sharing options...
Soma Posted January 15, 2013 Share Posted January 15, 2013 <?php function sitemapListPage($page,$siteMap='') { $siteMap .= "<li><a href='{$page->url}'>{$page->title}</a> "; if($page->numChildren) { $siteMap .= "<ul>"; foreach($page->children as $child) { $siteMap .= "<li><a href='$child->url'>$child->title</a></li>"; sitemapListPage($child,$siteMap); } $siteMap .= "</ul>"; } $siteMap .= "</li>"; return $siteMap; } $outMain .= "<ul class='sitemap'>"; $outMain .= sitemapListPage($pages->get("/")); $outMain .= "</ul>"; You need to pass along the variable. $siteMap='' argument is default to avoid passing an empty one. If defined it will get overwritten ans passed along. 1 Link to comment Share on other sites More sharing options...
Martijn Geerts Posted January 15, 2013 Share Posted January 15, 2013 (edited) function siteMap($page, $output='') { $output .= "<li><a href='{$page->url}'>{$page->title}</a>"; if($page->numChildren) { $output .= "<ul>"; foreach($page->children as $child) $output .= siteMap($child); $output .= "</ul>"; } $output .= "</li>"; return $output; } $homepage = $pages->get("/"); $siteMap = "<ul>" . siteMap($homepage) . "</ul>"; Think this will work Lesson: - first look if Soma, Diogo, Nik, Ryan, etc. etc. are active on the forum. - then, don't post at all ( cause they will be first ) Edited January 15, 2013 by Martijn Geerts 3 Link to comment Share on other sites More sharing options...
MarcC Posted January 15, 2013 Author Share Posted January 15, 2013 Thanks guys. I learned some new stuff today Link to comment Share on other sites More sharing options...
Martijn Geerts Posted January 15, 2013 Share Posted January 15, 2013 (edited) Actually had the same issue as you had marc. Soma solved that for me then. I left out the tab & new-line as it provides more flexibility in CSS. for example: ul { display: block; text-align: center; } li { display: inline; } This way you don't have the extra "white space" between the li items & you can text-align the li's. For navigations etc. I use a modified MarkupSimpleNavigation from Soma that don't output any tab, newline or any other white-space thingy. Hopefully Soma will simplify his module & leave them out by default. (I only use generated source if I'm not ripping JS ) example: http://codepen.io/anon/pen/FDrim Edited January 15, 2013 by Martijn Geerts 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now