Jump to content
AnotherAndrew

Sample text in editor

Recommended Posts

Does anyone have suggestions on how to put in formatted sample text in a textarea editor? For example, I want to have several templates and for each body content textarea field, I would place in sample text that is formatted accordingly. Then a user would simply highlight the text, put in their text, and everything is nice and formatted.

Would I need to create my own textarea module to do this?

Share this post


Link to post
Share on other sites

I don't know of a way that you can do this at present (short of making a module to do it). But if you need text formatted in a certain way, it's best to split the components of it into separate fields so that you can ensure that any formatting that happens is separated from the content.

Share this post


Link to post
Share on other sites

I use a tinyMCE inputfield copy in my site folder to do such stuff using the tinyMCE template feature. You can provide as much templates as you want ,and let's you select/preview one, then it will insert the html of the template. Template are just snippets of html and put in a folder as name.html files. You then define what and where they are using the config. http://www.tinymce.c...Plugin:template

Share this post


Link to post
Share on other sites

Soma, brilliant! I will give that a shot!

Quick question, and perhaps I should try before asking, but how do you associate the template with your various text fields?

Share this post


Link to post
Share on other sites

Soma, I figured it out. Rather easy.

It would be awesome if there was a default template that was already associated with the tinyMCE editor. And even better, it automatically goes into the editor field.

Share this post


Link to post
Share on other sites

Glad you figured it out! Mind telling what you did?

Concerning this I was about to soon find a solution to add templates easier, and per field. Ryan recently added a custom css and a textarea for additional config for tinymce configuration. Where each line would be a key:value. Testing now I found that how it's done currently, it doesn't work with adding a "template_templates:[{ ... }]" config. Because it expects to be a javascript object and not a string to work correctly. I'm working on some js vodoo to make it work in such cases. Just need a better solution than I have right now.

If this is done, adding "bramus css extras" to it will make it much more configurable out of the box. I hope Ryan is in for it. :)

Share this post


Link to post
Share on other sites

Ok I got it working so the core tinyMCE inputfield will allow custom configs with javascript objects like the "template_templates" uses [{..}]

I just sent a pull request for Ryan. https://github.com/r...essWire/pull/92

This looks something like the following and allows to specify templates per field, and put templates where you want :

(the last line in the screenshot is just testing... "force_br_newlines", trust me you don't want that true :) )

post-100-0-91253400-1332457010_thumb.png

Share this post


Link to post
Share on other sites

Sorry guys I spoke too soon. I didn't figure it out.

Soma, I would look at your suggestions and report back. Thanks for the input!

Share this post


Link to post
Share on other sites

Soma, it looks like this is little out of my league of php skill and that it does need some wizardy from Ryan.

This would be a very beneficial addition to the PW core and I do hope that Ryan agrees to it. I suppose that for now, I can not implement until Ryan puts this in the core.

I'm drawing my inspiration from a buddy of mine who develops in Cold Fusion who uses this to help wayward clients find / choose / selects how to best format a body of text to fit within the site's design. Here is an example of what it would look like, albeit in CF:

UtXyC.png

Share this post


Link to post
Share on other sites

Soma, it looks like this is little out of my league of php skill and that it does need some wizardy from Ryan.

This would be a very beneficial addition to the PW core and I do hope that Ryan agrees to it. I suppose that for now, I can not implement until Ryan puts this in the core.

I'm drawing my inspiration from a buddy of mine who develops in Cold Fusion who uses this to help wayward clients find / choose / selects how to best format a body of text to fit within the site's design. Here is an example of what it would look like, albeit in CF:

Andrew, I don't quite understand. This has nothing to do with php at all. It's plain javascript. Nothing very special about it, just update the /wire/modules/Inputfield/InputfieldTinyMCE/InputfieldTinyMCE.js with changes I've done. I attached the file (github pull request just shows parts) for easy update if you want to try it before Ryan puts it in.

Once done, you can put a configuration as in my previous post's screenshot. Create a folder in your site folder and use the path to that html template like for example "/site/templates-tinymce/mytemplate.html". Add the plugin string "template" and the button "template" into the appropriate fields. Done. No php at all. :)

InputfieldTinyMCE.js.zip

Share this post


Link to post
Share on other sites

Soma, sorry, I didn't fully understand your post until today.

Your solution works but I am getting an error in tinymce telling me that access is denied to that directory. (You don't have permission to access /site/templates/templates-tinymce/main-content.html on this server.) The permissions on the directory is set to 755. I seem to remember tinymce having problems like this....

Did you run into this?

Share this post


Link to post
Share on other sites

No, but I'm sure it's a permission problem with ftp user vs apache user. Try set it to 0777. Otherwise you should contact your hosting staff.

Also I'm currently working on getting more options to TinyMCE. Might wanna test this?

Share this post


Link to post
Share on other sites

Alright, I'll check with them. And sure I would love to help test. I never knew of all the misc things you could do with tinymce. I'll check out your post....

Share this post


Link to post
Share on other sites

Soma, I checked with my host and they said that the problem was with the htaccess file and a rule not allowing access to the directory. But that doesn't seem correct. Or does it?

I assume they are looking at this:

 # Access Restrictions: Protect ProcessWire system files (part 2)
 # -----------------------------------------------------------------------------------------------
 RewriteCond %{REQUEST_URI} (^|/)\.htaccess$ [NC,OR]
 RewriteCond %{REQUEST_URI} (^|/)site/assets/(cache|logs|backups|sessions|config|install)($|/.*$) [OR]
 RewriteCond %{REQUEST_URI} (^|/)site/install($|/.*$) [OR]
 RewriteCond %{REQUEST_URI} (^|/)site/config\.php$ [OR]
 RewriteCond %{REQUEST_URI} (^|/)(wire|site)/templates-admin($|/|/.*\.(php|html?|tpl|inc))$ [OR]
 RewriteCond %{REQUEST_URI} (^|/)site/templates($|/|/.*\.(php|html?|tpl|inc))$ [OR]
 RewriteCond %{REQUEST_URI} (^|/)site/assets($|/|/.*\.php)$ [OR]
 RewriteCond %{REQUEST_URI} (^|/)wire/(core|modules)/.*\.(php|inc|tpl|module)$ [OR]
 RewriteCond %{REQUEST_URI} (^|/)site/modules/.*\.(php|inc|tpl|module)$ [OR]
 RewriteCond %{REQUEST_URI} (^|/)(COPYRIGHT|INSTALL|README|htaccess)\.txt$ [OR]
 RewriteCond %{REQUEST_URI} (^|/)site-default/
 RewriteRule ^.*$ - [F,L]
 #

Share this post


Link to post
Share on other sites

I'm not really sure, but the restriction is for direct access in the browser by visitors... not on the server scripts. Still there seems to be an issue with permission I guess.

Anyone else?

Share this post


Link to post
Share on other sites

All I'm trying to do is reference /site/templates/templates-tinymce/foo.bar. There shouldn't be any permissions problem. Could it be a permissions problem with tinymce?

Share this post


Link to post
Share on other sites

I encourage you to try the other thread, as it does the same and even more and will be replace this. I just figured a better way to include templates too.

It's possible that you have PW installed in a subdir? Try the path in your browser directly, it should load the file.

Share this post


Link to post
Share on other sites

Pardon me, sort of hijacking the thread, but why don't you use standard ProcessWire fields for the structured data? (Like title, author, who? when? etc)

Share this post


Link to post
Share on other sites
I'm not really sure, but the restriction is for direct access in the browser by visitors... not on the server scripts.

That's correct, the .htaccess file is blocking access to /site/templates/ (and below), but only for files with these extensions: php, inc, htm, html, tpl. This is for security, since files in there are meant to be parsed by ProcessWire, not direct browser access.

All I'm trying to do is reference /site/templates/templates-tinymce/foo.bar

As long as its not one of those extensions above, PW shouldn't be blocking it. Though you may prefer to move it outside of PW's templates dir and perhaps into something like /site/tinymce-templates/.

why don't you use standard ProcessWire fields for the structured data? (Like title, author, who? when? etc)

I agree with this -- I think it's far preferable to use PW fields for this kind of stuff. It's definitely not a best practice to use something like TinyMCE for keeping structured data. (Though technically, I suppose the markup coming from TinyMCE could still be considered structured data if it's kept semantic.) This approach seems like something that one would do in some other CMS that doesn't have the ability to adequately manage custom fields. I don't understand using the approach here, but I also like to see that this can be done with TinyMCE. I'm sure there are times when this could be handy. I also know that everyone in this thread knows what they are doing and are already familiar with when and where they want to use PW fields. So I'm sure there are good reasons for taking this route. For instance, if you knew you never needed the data to be searchable at the field-by-field level, and didn't need it to be portable beyond the current need, then you might reduce the load of custom fields in your system by taking this TinyMCE template approach.

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 flydev 👊🏻
      Hello,
      I would like to present you a new module which aim to facilitate the productivity of your editors/publishers when working on ProcessWire.
      The idea begun when my co-worker told me that when typing in ProcessWire CkEditor field he was feeling "loosing motivation" when writing big wall of text and/or inspiration. So he opened his web-browser and show me a site looking to Wordpress - feel free to put your preferred emoji here - then he opened Gutenberg... typed some text and moving some "blocks".
      I understood immediately why he got this feeling with CkEditor. If you or your client feel like this guy, then you will love this module !
       
      What is currently supported ?
      Features
      Auto-save Medias upload support HannaCode support Blocks Implemented
      Heading Image Paragraph Embed Quote Code Link Table (beta) Block Delimiter Raw HTML Note (custom block markup) Feature Request
      Frontend Edition   
      And there you go for the preview - sorry I am to lazy and bad at typing text so I had a copy/pasta moment :
       

       
      Module featured in the ProcessWire Weekly #317 - Thanks @teppo
    • By DV-JF
      Hey girls and guys,
      I'll want to open this thread in order to discuss a main problem I've run into with following setup:
       
      I'm maintaining a site where different URLs are directed to the same folder. In site/ready.php the $user->language is set based on the $config->httpHost
      <?php /* Set language based on the domain and user is not logged in */ /* Slovenian */ if( $config->httpHost == "www.domain.si" || $config->httpHost == "domain.si" || $config->httpHost == "domain.si.local") { if (!($user->isSuperuser())) $user->language = $languages->get('si'); } /* German */ elseif( $config->httpHost == "www.domain.at" || $config->httpHost == "domain.at" || $config->httpHost == "domain.at.local" || $config->httpHost == "domain.ch" || $config->httpHost == "www.domain.ch" || $config->httpHost == "domain.de" || $config->httpHost == "www.domain.de") { if (!($user->isSuperuser())) $user->language = $languages->get('default'); } /* Croatian */ elseif( $config->httpHost == "www.domain.hr" || $config->httpHost == "domain.hr" || $config->httpHost == "domain.hr.local") { if (!($user->isSuperuser())) $user->language = $languages->get('hr'); } /* English */ elseif( $config->httpHost == "www.domain.eu" || $config->httpHost == "domain.eu" || $config->httpHost == "domain.eu.local") { if (!($user->isSuperuser())) $user->language = $languages->get('en'); } /* Italian */ elseif( $config->httpHost == "www.domain.it" || $config->httpHost == "domain.it" || $config->httpHost == "domain.it.local") { if (!($user->isSuperuser())) $user->language = $languages->get('it'); } The homepage (id=1) has following settings:

      As you can see German (Deutsch) is set as default language. Everything is working nice and fine and I'm really happy with this kind of setup but now there are some new requirements, which causes me quite a headache :
      I've to add some pages only in one or two languages (they should not be present in German) I've to create some editor roles that are allowed to only edit (can be done with https://processwire.com/docs/user-access/permissions/#multi-language-page-edit-permissions) & add pages to their specific language. What I've found out so far:
      The default language can't be disabled and must always be present (though this would be in my eyes the easiest solution) Creating my own "language select field" - example here: won't work in this case because I've to rely on the native languages in order to setup the right permissions for editors. There seems to be some solutionsbut I think these won't match for me because I've to think about handling editors and permissions, too. After searching and searching, scratching my head and searching and searching again, the only possibility that comes to my mind is to add another language for German and assign this language to the specific URL's instead of the default language.
      The advantages with this solution for me:
      I could activate or deactivate any language on any page Editors which are allowed to add pages can get the permission page-edit-lang-default without affecting the German pages. The disadvantages:
      All multi-language-fields will have an empty tab for the default language - this may irritate editors a lot Seems to me like a lot of work to do because I've to copy the language field nearly for 1000 pages/repeaters (maybe I'll find an SQL query) My questions:
      How would you handle this task? Could my setup be optimized in a completely different way? If I go for my solution (adding another language for German) would it be possible to hide the language tab for default language in any way?  If some points aren't clear enough please don't hesitate to ask.
      Many greets...
    • By Mustafa-Online
      Did any one tried to integrate "WordPress New Editor" into ProcessWire ??
      I did some searches and I found this Repo on Github: https://github.com/front/drupal-gutenberg Which allows Drupal Users to use Gutenberg.
      Any Thoughts ?

       
    • By MilenKo
      Hello guys.
      I've decided to get brave and start my first delayed output profile for a remake of my knowledge sharing profile. It went all.good so far but I decided to make it multilingual as to fit the users needs.
      For starters, added a field named: image_single and limited the input to one image as this would be used for the logo. Added.the markup to allow the front end editing (method D or direct edit tag to the <img>. After double clicking on the image, I see the pop-up showing up for a second and then closes. As far as there are no errors in the logs, I am a bit stuck to find the reason. I've read earlier that some users had issues with multilingual fields but could not find anything to point me to the right direction. Any ideas or suggestions?
    • By MilenKo
      Hello guys. I feel a bit ashamed of this fact but I just needed to add an image with some text wrapped around it using CKEditor and I simply can't achieve that. I have an image field attached to the template (called images) and it is showing promptly the uploaded images. I am able to manipulate the image and I set its alignment to left side. Then I add some text and I can see in CKEditor that the text is properly surrounding the image. However, once I save the page and view it, it shows the text under the image or only a line is staying asside the image and the rest is under the image again. As far as the field used for the text (body) is set to TextMultiLang and I did not added any text formatters and chose the content type to be HTML/Markup.
      In my CSS I've added some of the PW styles for the alignement as per some posts here but that did not help either. Something I am missing again?
       
       
       
       
×
×
  • Create New...