tpr Posted September 5, 2015 Share Posted September 5, 2015 MultiValue Textformatter for ProcessWire Set flexible data structures in "key = value1, value2, ..." format to use as variable groups in templates. Great for general site settings, social links, menus, etc. Converts contents of textarea field "social_links" from this: @ url ::: title ::: target Facebook = https://facebook.com/mycompany ::: Follow us on Facebook ::: _blank Linkedin = https://www.linkedin.com/mycompany ::: NULL ::: _blank Email = #contact ::: Contact to an object to be used like this: echo $page->social_links->facebook->title // result: "Follow us on Facebook" echo $page->social_links->email->title // result: "Contact" Putting it together: <ul> <?php foreach($page->social_links as $item) { ?> <li> <a href="<?php echo $item->url; ?>" target="<?php echo $item->target; ?>" title="<?php echo $item->title; ?>"> <?php // name is the original key echo $item->name; ?> </a> </li> <?php } ?> </ul> Syntax: @ header1 ::: header2 ::: header3 Key = value ::: value ::: value [ ::: ...] Another key = value ::: value [...] More info: Modules directory GitHub Feedbacks and suggestions are welcome. 13 1 Link to comment Share on other sites More sharing options...
tpr Posted September 10, 2015 Author Share Posted September 10, 2015 Updated to version 1.1.0 on GitHub: fixed wrong return if header rows were present fixed extra items when looping over a field moved TFMultiValue and TFMultiValueRow classes to separate files 1 Link to comment Share on other sites More sharing options...
tpr Posted September 12, 2015 Author Share Posted September 12, 2015 Mentioned in today's weekly, thanks! (I'm glad I made some important changes a few days earlier ) 1 Link to comment Share on other sites More sharing options...
tpr Posted November 21, 2015 Author Share Posted November 21, 2015 Available also from the modules directory: http://modules.processwire.com/modules/textformatter-multi-value/ 1 Link to comment Share on other sites More sharing options...
spercy16 Posted July 28, 2020 Share Posted July 28, 2020 Okay, I'm a noob to PW, as well as this module, and cannot figure out how to simply loop through a few videos that I have in a textarea field. Here's the code I'm using (that's probably wrong): <?php foreach($page->videos as $video) { echo '<div class="lazyload">' . $video . '"></div>'; } ?> I get this error on my page and can't figure out how to fix it: : Invalid argument supplied for foreach() in I'm a noob with PHP too and haven't quite figured out the foreach loop yet. I've looked at the PW documentation but haven't (quickly) found anything that explains it in detail. Any help would be much appreciated. FYI, I'm using the module TextformatterVideoEmbed as well to parse the videos from Youtube. I basically just have them listed in my page's textarea like this: <p>https://youtu.be/x0AHpsFVC9w</p> <p>https://youtu.be/x0AHpsFVC9w</p> <p>https://youtu.be/x0AHpsFVC9w</p> <p>https://youtu.be/x0AHpsFVC9w</p> Obviously they'll be unique links once the page goes live. The TextformatterVideoEmbed module requires them to be in <p> tags before exporting them to the page or I would just use the <p> or some other tag in the template file. Link to comment Share on other sites More sharing options...
teppo Posted July 28, 2020 Share Posted July 28, 2020 2 hours ago, spercy16 said: I get this error on my page and can't figure out how to fix it: : Invalid argument supplied for foreach() in I'm a noob with PHP too and haven't quite figured out the foreach loop yet. I've looked at the PW documentation but haven't (quickly) found anything that explains it in detail. [...] FYI, I'm using the module TextformatterVideoEmbed as well to parse the videos from Youtube. I basically just have them listed in my page's textarea like this: <p>https://youtu.be/x0AHpsFVC9w</p> <p>https://youtu.be/x0AHpsFVC9w</p> <p>https://youtu.be/x0AHpsFVC9w</p> <p>https://youtu.be/x0AHpsFVC9w</p> Obviously they'll be unique links once the page goes live. The TextformatterVideoEmbed module requires them to be in <p> tags before exporting them to the page or I would just use the <p> or some other tag in the template file. If you look at the first post in this thread, you can see that this module requires a specific format in the texarea ("Converts contents of textarea field..." etc.) If what you've pasted above is literally the contents of your textarea field, then it won't work with this textformatter. Note, though, that this module and Textformatter Video Embed are probably not compatible out of the box due to different format requirements. Depending on your use case you could perhaps use PHP's explode() or preg_split() to split the value of your textarea field into an array (which could then be used in foreach), but it also kind of sounds like a Repeater field would make more sense in this case. 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