We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 47717
    • 144 Posts
    Hi there,

    Is it possible, to define certain html code, in a tinyMCE content field, that can NOT be changed by a user ?

    I would put some raw html div's and area's, and the user should only be able to change the text and images.
    Because if I put now some html in, then the user can in non-html mode, easily accidently delete whole div area's or predefined elements with classes.

    This would be a huge time saver, as I wouldn't need to cut and split all parts in different TV's.

    Thanks ! [ed. note: sriananda last edited this post 11 years ago.]
      • 30585
      • 833 Posts
      There's an a way to customize tinMCE's toolbar in system settings. You could remove the option to edit the html source code. This should take care of that partially although a user can get around this by changing the formatting (which can also be turned off in system settings). I personally prefer tinyMCEWrapper -- a far better looking and more flexible option. Stuff like this is easily modifiable with this new addon.
        A MODx Fanatic
        • 47717
        • 144 Posts
        Quote from: treigh at Oct 13, 2015, 07:13 PM
        There's an a way to customize tinMCE's toolbar in system settings. You could remove the option to edit the html source code. This should take care of that partially although a user can get around this by changing the formatting (which can also be turned off in system settings). I personally prefer tinyMCEWrapper -- a far better looking and more flexible option. Stuff like this is easily modifiable with this new addon.

        What an awesome tip !! Thanks.

        So if I switch of the possibility to edit html and formats, the user can only edit the text ?
        If he deletes a whole bunch of text encapsulated in div, and he keeps on deleting,even with those switched off, he would be deleting the hidden html or not ?
          • 30585
          • 833 Posts
          The user will certainly be able to remove those divs by deleting everything in the editor. I'm wondering if what you're protecting cannot be protected differently. Can you elaborate a bit more?
            A MODx Fanatic
            • 47717
            • 144 Posts
            Hey,

            I installed your link, and tinyMCEWrapper looks nice and slick, and is directly added to two other standard input fields. smiley

            So now certain pages have lots of stylings, sidebars, divs and regions with different css classes.
            I would love not to split that page in 12 TV's.
            A bit maybe like "redactor" or so. I only want the plain text to be editable, nothing else can be deleted or altered.
            It's like with other cms you can "lock" ie a p tag with a class attached within a div. The user changes, adds or deletes plain text within those predetermined wrappped html.
            This would makr converting html pages so much faster, easier and straightforward.

            Is that possible ?
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              Only with something like ContentBlocks, which is why ContentBlocks was developed.

              In cases like that, I use TVs along with Form Customization to hide fields I don't want the user to be able to change as well as placing the TVs in the form region where I want them.
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 42562
                • 1,145 Posts
                donshakespeare Reply #7, 11 years ago
                Quote from: sriananda at Oct 14, 2015, 11:23 AM
                ...
                Is that possible ?
                Anything is possible, clientside with clientside material.

                But let me explain something: either you abandon ship and go the route of ContentBlocks, or you put on a constructor's hat, brace the flames, and achieve what you want with your current setup.
                Here is an idea for you. In the manager, you are using textareas. These are a bit doggish. Anything in them is editable, content and whatever else you have added.
                Well, the idea of proper design is to make only content available to the user in the first place.
                If you like DIYs see
                http://www.tinymce.com/forum/viewtopic.php?id=23405

                some more related ideas
                http://stackoverflow.com/questions/7522848/contenteditable-false-inside-contenteditable-true-block-is-still-editable-in-ie8
                http://jsfiddle.net/haxhia/uUKPA/3/

                Similar method I have used successfully (which is almost ready for publication, in fact is in the next release of TinymceWrapper - frontend only)
                You can hack it and achieve what you want.

                1. Clone-convert all textareas to contenteditable divs
                2. Now add the attribute contenteditable = false to any and all parent elements you want their content locked.
                In fact, you don't need #2: due to the contenteditable attribute, the containing element cannot be removed, only its contents.
                3. When you hit save, the abominable textareas get updated with the contents of the DIVS and then saves.

                So
                <textarea id="#ta">
                  <p class="cannotNotDeleteMe">
                    I am the notorious MODx manager textarea
                  </p>
                  <p class="cannotNotDeleteMe">
                    I am the notorious MODx manager textarea
                  </p>
                </textarea>

                becomes (test this in jsfiddle)
                <div contenteditable="false" data-origin="ta">
                    <p class="canNotDeleteMe" contenteditable="true">
                      this is editable
                    </p>
                    <p class="canNotDeleteMe" contenteditable="true">
                      this is editable
                    </p>
                </div>

                And yes, TinyMCE handles this very nicely, you just have to think through thoroughly.
                  TinymceWrapper: Complete back/frontend content solution.
                  Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
                  5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.