kathep Posted December 29, 2014 Share Posted December 29, 2014 I am trying to output my first instance of multiple fields from a pagearray, and only have partial success. My problem involves the following fields and templates: assignment.phpreadings_from_list readings.phptitle book_section_reading_time Using either of the following code options: Code option 1, adapted from @teppo's solution here: // using pages->find to display muliple values from a PageArray // only one selection displays though $reading = $page->reading_from_list; $reading_w_heading = ''; $reading_w_heading = $pages->find(); foreach ($reading as $read) { $reading_w_heading = "<p><a href='$read->url'>" . $read->title . "</a> - " . $read->book_section_reading_time->title . " of reading</p>" ; } $content = <h4>Read:</h4>" . $reading_w_heading; Code option 2, adapted from @nico's solution here: $reading_w_heading = ''; $reading = $page->reading_from_list; if($reading instanceof PageArray) { foreach($reading as $read) { $reading_w_heading = "<p><a href='$read->url'>" . $read->title . "</a> - " . $read->book_section_reading_time->title . " of reading</p>" ; } } $content = <h4>Read:</h4>" . $reading_w_heading; Outputs this result: Despite more than one item selected in the field readings_from_list: I suspect this has a really simple solution, but my knowledge is so basic that I can't figure it out. Frustrating! Could someone point out to me where I am going wrong? Note: I don't want to use echo because I am using _init.php and _main.php from the PW_default template, and like this system very much. However, when I echo anything, it appears above the _main.php content (and therefore above my main navigation) - suboptimal. Link to comment Share on other sites More sharing options...
Nico Knoll Posted December 29, 2014 Share Posted December 29, 2014 I don't see the problem here? Or what do you expect your output to look like? Link to comment Share on other sites More sharing options...
horst Posted December 29, 2014 Share Posted December 29, 2014 Hey @kathep, it is simply missing a dot here, that concatenate your multiple results: $reading_w_heading .= "<p><a href='$read->url'>" .... $reading_w_heading .= "concatenate me"; (more here) 3 Link to comment Share on other sites More sharing options...
kathep Posted December 29, 2014 Author Share Posted December 29, 2014 Ah, @horst thank you! You have stopped many hours of frustration! @nico, I wanted the output to look like this: which it now does, thanks to @horst reminding me of the concat dot in your original solution. BTW, I am very grateful to have access to such a helpful community of processwire fans. This just adds to the already very awesome experience of using processwire. 3 Link to comment Share on other sites More sharing options...
horst Posted December 29, 2014 Share Posted December 29, 2014 ... BTW, I am very grateful to have access to such a helpful community of processwire fans. This just adds to the already very awesome experience of using processwire. ... and not to forget that your PHP skills will raise too. BTW, how have you found PW? Link to comment Share on other sites More sharing options...
kathep Posted December 29, 2014 Author Share Posted December 29, 2014 Yes, I am learning PHP quite fast using PW. I didn't know any before last week I think I found PW by googling for a lightweight CMS. The bloated options of the big, popular CMSs, and the limitations of certain small open source CMSs were unsuitable for my needs. I hoped there was something better. I find developing in PW quite addictive. I'm not sure if its the full control of information architecture, or how much fun php is, or the ease of use of the PW API. Do others find it addictive? Anyway, I am having a lot of fun with it. 3 Link to comment Share on other sites More sharing options...
pwired Posted December 29, 2014 Share Posted December 29, 2014 Yes, I am learning PHP quite fast using PW. I didn't know any before last week Yup, join the club Kathep, processwire is the only cms/cmf (that i know of) that comes with automatic php learning. 2 Link to comment Share on other sites More sharing options...
kathep Posted December 29, 2014 Author Share Posted December 29, 2014 Yup, join the club Kathep, processwire is the only cms/cmf (that i know of) that comes with automatic php learning. I don't know about 'automatic'. My php learning has been painfully manual. Link to comment Share on other sites More sharing options...
horst Posted December 30, 2014 Share Posted December 30, 2014 I find PW and PHP addictive. And here is what others say: google-4-addictive EDIT: corrected broken google link 1 Link to comment Share on other sites More sharing options...
kathep Posted December 30, 2014 Author Share Posted December 30, 2014 Ah, so it isn't just me then 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