We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21255
    • 215 Posts
    (MODx-version 0.9.1)

    Hides the content editor when using a template that doesn’t contain the [*content*]-variable.

    I have some documents on my site which only consist of Template Variables and don’t have any further content. For our customers convenience, I needed the possibility to hide the content editor in these cases so that only the sections for document properties and template variables are shown.

    /*
    You need to change mutate_content.dynamic.action.php (line 872) to this:
    <?php if(($content['type']=="document" || $_REQUEST['a']==4) && $content['nocontent'] != true ) { ?>
    */
    
    global $content;
    $e = &$modx->Event;
    
    switch($e->name) {
    
      case 'OnDocFormPrerender':
    
        /* Get current template id */
        $template_id = ($content['template'] != "" ?  $content['template'] : $modx->config['default_template']);
       
        /* Get template's content */
        $table = $modx->getFullTableName("site_templates");
        $result = $modx->db->select("content", $table, "id = $template_id");
        if($modx->db->getRecordCount($result)>0) {
          $template = implode($modx->db->getRow($result));
          if(strpos($template, '[*content*]') === false) {
            /* Template doesn't use [*content*] */
            $content['nocontent'] = true;
            return;
          }
        }
        break;
    
      default:
        return;
        break;
    
    }
    


    I love MODx for giving me the freedom to do this. smiley
      • 32963
      • 1,732 Posts
      This is very cool smiley Nice plugin.
        xWisdom
        www.xwisdomhtml.com
        The fear of the Lord is the beginning of wisdom:
        MODx Co-Founder - Create and do more with less.
        • 6726
        • 7,075 Posts
        Just what I needed, also to avoid my customer being confused : thanks a lot for this !

        How do you use it ? Place it at the top of the content container ?
        Just a thought : could this simply be integrated into MODx ? I guess if the [*content*] is empty then no need to have to content fields appear in the editor, uh ?
          .: COO - Commerce Guys - Community Driven Innovation :.


          MODx est l&#39;outil id
          • 32241
          • 1,495 Posts
          Hey david, I think you need to create a new plugin that listen to event "OnDocFormPrerender".

          Then inside your manager files, which means you need to hack into the core system, you need to change manager/actions/dynamic/mutate_content.dynamic.action.php file on line 872 to this code
          <?php if(($content['type']=="document" || $_REQUEST['a']==4) && $content['nocontent'] != true ) { ?>
          


          I haven’t test this yet, but I think that’s the way to do it.

          Sincerely,
            Wendy Novianto
            [font=Verdana]PT DJAMOER Technology Media
            [font=Verdana]Xituz Media
            • 6726
            • 7,075 Posts
            Okay thanks for the explanation, I had gotten the hacking the core part, but the plugin with OnDocFormPrerender ticked part I didn’t yet got that.

            Thanks !

            Edit : Okay I did this. Copied/pasted the plugin code, checked OnDocFormPrerender in System Events > Documents but when I access the page based on the template without [*content*] (only got TVs), the QuickEdit content field are still there...
              .: COO - Commerce Guys - Community Driven Innovation :.


              MODx est l&#39;outil id
              • 21255
              • 215 Posts
              Sorry, it sticks to the backend and so it doesn’t work with the quickedit module.
                • 6726
                • 7,075 Posts
                OK no problem, that’s already a very good thing. It works like a charm smiley

                I’ve been meaning to ask how I can hide field in quickedit, it’s more of a quickedit question I guess. Anyway, thanks for this it will be very useful !
                  .: COO - Commerce Guys - Community Driven Innovation :.


                  MODx est l&#39;outil id
                  • 17883
                  • 1,039 Posts
                  Unbelievable, just thought about that (also have a Template with lots of TVs and no [*content*] ) and here is the solution shocked

                  Thx for sharing it!

                  Greetz Marc
                    • 6726
                    • 7,075 Posts
                    Just one thing that I found out using this plugin : I often if not always use [*#content*] instead of [*content*] in my templates, to have the quickedit link available to content editors. The plugin doesn’t work if you work like I do... so I just edited the plugin

                     if(strpos($template, '[*#content*]') === false) 


                    Anyway, it’s a very handy plugin that avoid content editor’s confusion when you build pages with TVs and no content field...
                      .: COO - Commerce Guys - Community Driven Innovation :.


                      MODx est l&#39;outil id
                      • 6726
                      • 7,075 Posts
                      Tip : In 0.9.5 rev 1687, you can find the appropriate line to edit @line 981
                        .: COO - Commerce Guys - Community Driven Innovation :.


                        MODx est l&#39;outil id