Jump to content
danielholanda

creating space between text paragraph in textarea field

Recommended Posts

I found this problem which I dont know how to solve. I created a field which is a textarea. The client will place her information inside and that will be echoed into the web. Simple and clear. The only thing is that the client has long text so he will create paragraphs. In the box of the textarea in the CMS PW you can create text and with the keyboard ENTER you can make paragraphs. Once saved it still remains with paragraph format as the spaces are respected in processwire.

But...

In the web you only see one block of text. What method has to be done so the client can create spaces between the text?

Thanks Dani

Share this post


Link to post
Share on other sites

I'm not sure if I understand 100% what you want to achive, but I think you just need to do this in PHP when "echoing" the text from the textarea:

echo nl2br($text);

You'll have "<br />" Tags and not paragraphs in your html. Maybe that's ok? ;-)

Share this post


Link to post
Share on other sites

Well, I thought there could be a solution as such... but I wouldnt like to say to the client she needs to write <br> to make a paragraph separation. I would like she is free to create paragraphs pressing the usual ENTER keyboard. This should be easy to create. I dont know if I explained myself correctly.

With processwire you can create text fields. This is to give the service via CMS to write text in it. The client would like a text as this for example:

Maecenas venenatis pellentesque luctus. Vestibulum nunc dolor, cursus in tempor quis, aliquet at massa. Vivamus varius dapibus egestas. Maecenas nec suscipit sapien. Nam et nibh velit. Aliquam semper dui eu ipsum tristique mollis. Integer et nibh eu magna iaculis adipiscing nec eu odio. Nullam pulvinar viverra gravida.

Curabitur id vehicula diam. Maecenas consectetur aliquet quam sit amet dictum. Duis molestie vestibulum turpis at varius. Curabitur sodales laoreet dui egestas rhoncus. Cras elit risus, ullamcorper et vulputate vitae, placerat vitae purus. Cras at posuere risus. Morbi consequat eleifend libero vel ultricies. Morbi venenatis mattis arcu, et sagittis massa posuere a. Maecenas neque odio, hendrerit sit amet v

Clients can be quite picky with what they want. Most surely she wants to display the text look like this. So I would like that when the client writes text in the textfield it displays exactly what they have written. I put an image of the field I mean, as the chines say... better one image than 1000 words.

open to solutions :)

post-663-0-64739600-1347317728_thumb.png

Share this post


Link to post
Share on other sites

Two options: change it to rich text editor (edit the field and then details tab => Inputfield type => tinyMCE) or then add newlines to br textformatter (install it from modules, then edit the field and add the formatter from details tab).

Share this post


Link to post
Share on other sites

I was writing a reply yesterday when StopDaddy interfered. You now have all the info you need. but i'll post it anyways. Be sure to read.

I'm assuming that the field is of the type 'textarea' without TinyMCE. This does not actually create html <p> tags. So if you hit 'enter' two times when editing the field contents it visually looks like a paragraph but it are in fact two newline characters.

Newline characters are stored in the database but don't do anything visually when you echo it on the "web".

Wanze's suggestions works. There even is a text formatter already for that. In the PW admin go to "Modules". Scroll to the Textformatter section and install the "Newlines to XHTML Line Breaks" module. Now go to Setup->Fields. In the fields table look for the relevant textarea field. Click on it. Go to the details tab and choose aforementioned Text Formatter. If you now look at "The Web" it should all be good.

If all of this doesn't make sense to you or if your problem is somehow different you should read up on html and learn your tool (PW).

and/or

Provide us with a more detailed description of your problem and what you have already tried to solve it yourself. Things like looking at the generated html, corresponding CSS etcetera.

If i speak for myself but guess most of the forum members: We are more than willing to help, also with basic questions, but some effort on your part is required.

ps You should consider using a TinyMCE field because making look-a-like paragraphs generally isn't considered best practice

  • Like 1

Share this post


Link to post
Share on other sites

Hello,

Yes you guys were assuming correctly. I had the textarea without tinyMCE. Thank you the new module works smoothly.

Regarding the post of Sinnut. I have to begin asking these questions and learning via forums. This is how I learn any other program. At the begginng there are a lot of things to learn so you are forced to ask a lot of small details. Knowing this I learn everytime a bit more so I can also help others in a future. I think this is normal. For example this post is already converted into a manual, next time somebody has this same problem they will find this post.

Which documentation should I read to have known this answer to this question for example? I'm open to suggestions or kind of bibles I need to know. I like a lot processwire.

Greetings,

Dani

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By DV-JF
      Hey all, hope you're feeling well these days!
      Short question: Under "Setup > Templates" it's possible to sort the templates by last modified. Is this possible for fields view to?
      Long explanation:
      Currently I am in the process of programming a reusable template and often have to copy several fields & templates from different PW installations into my "master version".
      Therefore it would be good to see already in the field list when the last modification has taken place.
      Stay healthy & don't forget to wash you hands - many greets!
    • By Robin S
      This module is inspired by and similar to the Template Stubs module. The author of that module has not been active in the PW community for several years now and parts of the code for that module didn't make sense to me, so I decided to create my own module. Auto Template Stubs has only been tested with PhpStorm because that is the IDE that I use.
      Auto Template Stubs
      Automatically creates stub files for templates when fields or fieldgroups are saved.
      Stub files are useful if you are using an IDE (e.g. PhpStorm) that provides code assistance - the stub files let the IDE know what fields exist in each template and what data type each field returns. Depending on your IDE's features you get benefits such as code completion for field names as you type, type inference, inspection, documentation, etc.
      Installation
      Install the Auto Template Stubs module.
      Configuration
      You can change the class name prefix setting in the module config if you like. It's good to use a class name prefix because it reduces the chance that the class name will clash with an existing class name.
      The directory path used to store the stub files is configurable.
      There is a checkbox to manually trigger the regeneration of all stub files if needed.
      Usage
      Add a line near the top of each of your template files to tell your IDE what stub class name to associate with the $page variable within the template file. For example, with the default class name prefix you would add the following line at the top of the home.php template file:
      /** @var tpl_home $page */ Now enjoy code completion, etc, in your IDE.

      Adding data types for non-core Fieldtype modules
      The module includes the data types returned by all the core Fieldtype modules. If you want to add data types returned by one or more non-core Fieldtype modules then you can hook the AutoTemplateStubs::getReturnTypes() method. For example, in /site/ready.php:
      // Add data types for some non-core Fieldtype modules $wire->addHookAfter('AutoTemplateStubs::getReturnTypes', function(HookEvent $event) { $extra_types = [ 'FieldtypeDecimal' => 'string', 'FieldtypeLeafletMapMarker' => 'LeafletMapMarker', 'FieldtypeRepeaterMatrix' => 'RepeaterMatrixPageArray', 'FieldtypeTable' => 'TableRows', ]; $event->return = $event->return + $extra_types; }); Credits
      Inspired by and much credit to the Template Stubs module by mindplay.dk.
       
      https://github.com/Toutouwai/AutoTemplateStubs
      https://modules.processwire.com/modules/auto-template-stubs/
    • By DV-JF
      Hi, 
      I'm using this kind of setup (https://processwire.com/blog/posts/language-access-control-and-more-special-permissions/#language-page-edit-permissions) in order to control the page edit permissions. Now I'm wondering if it's possible to hide the "none-ediable" language-tabs instead of striking them through.

      Many greets...
       
    • By Robin S
      Another little admin helper module...
      Template Field Widths
      Adds a "Field widths" field to Edit Template that allows you to quickly set the widths of inputfields in the template.

      Why?
      When setting up a new template or trying out different field layouts I find it a bit slow and tedious to have to open each field individually in a modal just to set the width. This module speeds up the process.
      Installation
      Install the Template Field Widths module.
      Config options
      You can set the default presentation of the "Field widths" field to collapsed or open. Field widths entered into the Template Field Widths inputfield are only applied if the Edit Template form is submitted with the Template Field Widths inputfield in an opened state. "Collapsed" is the recommended setting if you think you might also use core inputs for setting field widths in a template context. You can choose Name or Label as the primary identifier shown for the field. The unchosen alternative will become the title attribute shown on hover. You can choose to show the original field width next to the template context field width.  
      https://github.com/Toutouwai/TemplateFieldWidths
      https://modules.processwire.com/modules/template-field-widths/
    • By Macaco
      Hi there, 
      I have two templates that should talk to each other. One is for events which should access a list of artists (eventually add a new artist) and their images related to that event; the second is the artist page, which the user should be able to add or remove events that they participated, also mentioning which images are related to each event.
      Some sort of feedback loop between the two.
      I have tried searching around the community and google, but maybe I'm not formulating the question properly. 
      Thank you all for the amazing work with Processwire and the community support. I have made a few websites with PCW yet I'm still quite between beginner and intermediate.
×
×
  • Create New...