bernhard Posted November 11, 2018 Share Posted November 11, 2018 Here are the docs: https://processwire.com/api/ref/wirearray/each/ I simply want to create a footer-menu... nothing fancy, but I thought instead of foreach I'd use the each() method... but some details are missing for this use: The method can return a concatenated string or an array of items. What I'd need - or at least what I think what I'd need - is that it returns an array of generated strings. The Problem: $pages->each("<a href='{$url}'>{$title}</a> | "); Results in Item 1 | Item 2 | If it returned an array with those strings I could simply do this: echo implode(" | ", $items); Using this syntax does also not work: $pages->each(["<a href='{url}'>{title}</a>"])); As it returns this crazy array where I can't use implode() either: My traditional way of doing this would be this: $del = ""; foreach($uk->home->rocktheme_footermenu as $p) { echo "$del<a href='{$p->url}'>{$p->title}</a>"; $del = " | "; }; But I think this would be nicer and feel more like PW: echo implode(" | ", $uk->home->rocktheme_footermenu->each("<a href='{url}'>{title}</a>")); Am I missing anything or would it be nice to have the Option of returning a simple array of strings? Link to comment Share on other sites More sharing options...
LostKobrakai Posted November 11, 2018 Share Posted November 11, 2018 Why not https://processwire.com/api/ref/wire-array/implode/ directly? Edit: … but you're right. Seems like WireArray::each really suffered from feature-creep. Reading the docs sounds like it's really inconsistant in what it does. 1 1 Link to comment Share on other sites More sharing options...
bernhard Posted November 11, 2018 Author Share Posted November 11, 2018 Thx again! I knew there was such a possibility but was looking all over the wrong spots ? echo $uk->home->rocktheme_footermenu->implode(" | ", function($p) { return "<a href='{$p->url}'>{$p->title}</a>"; }); Now it feels like PW again ? Link to comment Share on other sites More sharing options...
Recommended Posts