baymarketingco Posted October 17, 2016 Share Posted October 17, 2016 Hi, I can't get my head around this simple concept. What am I missing? I need a field that allows me to enter multiple lines of text. Let's take some JSON+LD input as an example: The alternateName field allows one to enter more than one name for a hotel. So I need a field that allows me to say, click a + button to add a new option for an alternate name, add the text, and then do so again, if I have another alternate name. This then obviously has to generate the proper code automatically. I'm thinking this would be an array??? I can't seem to find a solution. Perhaps it's a lack of understanding what I'm looking for. Another, somewhat related issue: How do I create HTML that only outputs when there is something to output? Let's take the same JSON+LD. Here's the code for that: <script type="application/ld+json"> "alternateName": "<?php echo $page->json_ld_alternateName; ?>", </script> Now, is there a way to REMOVE the whole alternatename line of code (or not make it show in the first place), if there is no json_ld_alternateName inserted by the user? Thanks! Link to comment Share on other sites More sharing options...
horst Posted October 17, 2016 Share Posted October 17, 2016 <?php // only render output if there is something set in field json_ld_alternateName if(strlen($page->json_ld_alternateName) > 0) { echo " <script type='application/ld+json'> 'alternateName: '{$page->json_ld_alternateName}', </script>\n"; } I wrap "doublequotes" around the php string and use 'singlequotes' for strings within the markup. If you run into situations where you also would need doublequotes within the markup, you can use them if you escape them with a backslash: <?php echo "<p>A string with 'singlequotes' and escaped \"doublequotes\"!</p>"; // will output: <p>A string with 'singlequotes' and escaped "doublequotes"!</p> 4 Link to comment Share on other sites More sharing options...
baymarketingco Posted October 17, 2016 Author Share Posted October 17, 2016 That is awesome. Thanks @horst! Works a charm. Now the other issue, if you could help. How do I create a field where I can enter one or more lines of text? In other words, stuff to populate json_ld_alternateName. I looked at the repeated field, but that seems to require info that's already present in the system. Likewise, the pagetable field requires something too. What I need is a field that allows me to add the alternate name, then add another, if applicable. Thanks! Link to comment Share on other sites More sharing options...
szabesz Posted October 17, 2016 Share Posted October 17, 2016 1 hour ago, blommie said: I looked at the repeated field, but that seems to require info that's already present in the system. Likewise, the pagetable field requires something too. Hi, What is wrong with repeaters in your case? Can you please elaborate? 1 Link to comment Share on other sites More sharing options...
baymarketingco Posted October 17, 2016 Author Share Posted October 17, 2016 Hi @szabesz, Thanks for your reply. Perhaps I don't understand how to set up a repeater field properly. If I use a repeater, I get an option to choose from a predefined list of choices. What I require is a field where I populate the text myself, with an option to add more text fields. Check the attached image to see what I'm aiming for. Hopefully it makes more sense than my words Link to comment Share on other sites More sharing options...
szabesz Posted October 17, 2016 Share Posted October 17, 2016 I know that using a repeater for such an input looks like a bit convoluted solution, because a repeater is designed to handle more than one field "during input", but if you only assign one filed to the Repeater you use, then you can get a similar behavior. With a little bit of admin CSS hacking, you might even be able to tweak it to make its UI less "verbose" (on the repeater field's Details tab settings you can even set its items to be "always open"). Note, that without ajax loading, you might not want to create more than 40-60 items for performance reasons (depending on your server config), see: This has been improved with the “ajax option” though:https://processwire.com/blog/posts/more-repeaters-repeater-matrix-and-new-field-rendering/ 1 Link to comment Share on other sites More sharing options...
adrian Posted October 17, 2016 Share Posted October 17, 2016 What about this new fieldtype: 2 Link to comment Share on other sites More sharing options...
Robin S Posted October 17, 2016 Share Posted October 17, 2016 11 hours ago, blommie said: How do I create a field where I can enter one or more lines of text? Besides Repeater and PageTable, there are Table and Multiplier in the ProFields package that can be used for repeating content. But for a simple repeatable text string you could just use a textarea field and explode() on newline to get an array of values. $values = explode("\n", str_replace("\r", '', $page->my_textarea)); 1 Link to comment Share on other sites More sharing options...
baymarketingco Posted October 19, 2016 Author Share Posted October 19, 2016 Thanks @szabesz, @adrian and @Robin S, for your replies. Will take a look at the json module. I think I struggle to grasp some of the concepts of PW. But I'm spending most of my free time reading up on it and watching vids about it. The profields module looks amazing. Might invest in that. Thanks again for your replies! Link to comment Share on other sites More sharing options...
BitPoet Posted October 19, 2016 Share Posted October 19, 2016 @blommie: I'm not sure JsonNativeField is going to fit your bill. While it supports an arbitrary number of entries, those are key => value pairs, much like regular fields with a name and value. You might want to look at the ChosenSelect Inputfield, which behaves as a tagging field and allows creating new "tags" (which are actually PW pages behind the scenes with the tag value as the title) on the fly if you enter a new name. Repeater and Page field types don't need you to have the pages used in them to already be present in the system. A page is just an entry in a table in the database, and if you use repeaters, the template configuration for these pages is even done behind the scene when you define the repeater field's parts (fields). If you're coming from other systems, the concept of using "full-blown" pages for simple data might seem a bit much, but because PW keeps things simple under the hood, it actually doesn't get much leaner database-wise. 2 Link to comment Share on other sites More sharing options...
baymarketingco Posted October 19, 2016 Author Share Posted October 19, 2016 @BitPoet the whole page thing definitely trips me up. I'll take a look at that module. I've also received an official document of authorisation from my wife to invest in the profields plugin, end of the month. (I'm the boss, as long as she allows me to be.) Thanks for your input! 3 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