Boost Posted May 30, 2023 Share Posted May 30, 2023 Hei, A little help here would be nice. So, I created a repeater field with a body and image fields. I named this repeater field sections. I added the field to my home template and use it on my page normally. Now on home.php template file, I try to output it like this: <div id="content"> <?php foreach($page->sections as $x) : ?> <?= $x->body ?> <?php endforeach ?> </div> But nothing shows up. Yes, I read the page https://processwire.com/docs/fields/repeaters/ Am I missing something? Link to comment Share on other sites More sharing options...
artfulrobot Posted May 30, 2023 Share Posted May 30, 2023 nothing shows up? or do you see <div id="content"></div> As in: it's just $x->body that's not outputting anything? It looks right to me; my code that uses repeater is similar. So to debug I would: check that you see the <div> - it's obvious, but I for one often hammer the keyboard for ages and then realise I've edited the wrong file or such...! use Tracy console on the page to inspect $page->sections and $page->sections[0] and $page->sections[0]->body. Is there data in there? not sure what my next step would be if there was data in there but it wasn't output as you have done. Check the text format filters? Sorry, probably not much help, but thought I'd chip in. (I'm relatively new here.) Link to comment Share on other sites More sharing options...
Boost Posted May 30, 2023 Author Share Posted May 30, 2023 Thanks. I do have some there Link to comment Share on other sites More sharing options...
diogo Posted May 30, 2023 Share Posted May 30, 2023 You say you created the field body in the repeater, but in that case, I would expect it to appear here besides the image field: To test the foreach, can you change your code to $x->id instead of $x->body to see if the IDs show up? Link to comment Share on other sites More sharing options...
aagd Posted May 30, 2023 Share Posted May 30, 2023 Did you enter some test content in that repeater? Link to comment Share on other sites More sharing options...
Boost Posted May 30, 2023 Author Share Posted May 30, 2023 @aagdyes, I did!@diogo sorry, but which Id are you talking about? Where can I find it? Link to comment Share on other sites More sharing options...
diogo Posted May 30, 2023 Share Posted May 30, 2023 1 minute ago, Boost said: @diogo sorry, but which Id are you talking about? Where can I find it? Every repeater item is given an ID that you can access inside a foreach with $item->id (or $x->id, in the case of your foreach). You can see on the screenshot that you posted, that the ID of your single repeater item is 1110. This would be just to see if your foreach is correct, but as I pointed out before, the most important is to understand why the body isn't even appearing in the array. You are sure you added the body to the repeater field, and not to the home template itself? Link to comment Share on other sites More sharing options...
Boost Posted May 31, 2023 Author Share Posted May 31, 2023 Ok, let me take a step back here: My repeater field: My template: My page: And here is my home.php <?php namespace ProcessWire; // Template file for “home” template used by the homepage ?> <div id="content"> <?php foreach($page->sections as $x) : ?> <?= $x->body ?> <?php endforeach ?> </div> My issue here is that if I changed the output to image, it works: <div id="content"> <?php foreach($page->sections as $x) : ?> <?= $x->image ?> <?php endforeach ?> </div> But it doesn't for body ? Link to comment Share on other sites More sharing options...
aagd Posted May 31, 2023 Share Posted May 31, 2023 Have you tried with simpler content for body? Seems like table is stripped from the output. Possibly the body field needs to allow some extra html tags (see body field settings). Link to comment Share on other sites More sharing options...
Boost Posted May 31, 2023 Author Share Posted May 31, 2023 Yes, I just tried, no luck. Link to comment Share on other sites More sharing options...
diogo Posted May 31, 2023 Share Posted May 31, 2023 Do you get any result when you output the body unformatted? <div id="content"> <?php foreach($page->sections as $x) : ?> <?= $x->getUnformatted('body') ?> <?php endforeach ?> </div> 1 Link to comment Share on other sites More sharing options...
Boost Posted May 31, 2023 Author Share Posted May 31, 2023 Yes!!! I got it! But why?? Link to comment Share on other sites More sharing options...
diogo Posted May 31, 2023 Share Posted May 31, 2023 Hm, the content is being striped by a text formatter or by some setting in TinyMCE. Do you have any text formatter added in the body field? You could also create a new item in the repeater and write only "test" in the body to see if works with the simplest content possible. Link to comment Share on other sites More sharing options...
Boost Posted May 31, 2023 Author Share Posted May 31, 2023 I did write only "test", and it did not work without getUnformatted Funny, because I don't remember changing any text formatter setting. Link to comment Share on other sites More sharing options...
diogo Posted May 31, 2023 Share Posted May 31, 2023 1 hour ago, Boost said: Funny, because I don't remember changing any text formatter setting. And, according to your screenshot, you didn't. The text formatters selector is empty. Since you have Tracy installed, What do you get in the tracy dumps if you bd() the body? <div id="content"> <?php foreach($page->sections as $x) : ?> <?php bd($x->body)?> <?= $x->body ?> <?php endforeach ?> </div> Link to comment Share on other sites More sharing options...
Boost Posted May 31, 2023 Author Share Posted May 31, 2023 Link to comment Share on other sites More sharing options...
diogo Posted May 31, 2023 Share Posted May 31, 2023 Ok, this is a bit puzzling. The string is there, but empty. If you add more items to the repeater, you get an empty string on all of them? Maybe you could also create a new tinymce field and add it to the repeater to see if it behaves in the same way. 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