Jump to content

Recommended Posts

Posted

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?

Posted

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.

Posted

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

Posted

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.

Posted

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. :)

Posted

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

Posted

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

Posted

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

Posted

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?

Posted

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?

Posted

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]
 #
Posted

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?

Posted

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.

Posted
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.

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
×
×
  • Create New...