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

    I don’t know which is the best way to do solve this "problem".
    I have a big modx site (more that 1000 docs) and I added the possibility to comment and vote some articles.
    The problem I have is that I don’t want to let these options available for all docs but only for some.

    I was thinking to use TV in order to have a checkbox in admin to let me choose if comments / votes will be available or not but I don’t know how can I check the tv value in a snippet like this

    if ($tv_value = 1) { $modx->getChunk($comments_chunk); }


    Thanks
    Sara

      • 23491 ☆ A M B ☆
      • 1,056 Posts
      Sara,

      One way you could easily perform this form of conditional logic is via the PHx plugin: http://wiki.modxcms.com/index.php/PHx

      Download URL: http://modxcms.com/PHx-1006.html
        Mike Reid - www.pixelchutes.com
        MODx Ambassador / Contributor
        [Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
        ________________________________
        Where every pixel matters.
        • 7231
        • 4,205 Posts
        Here is a snippet i just put together for a project to get a chunk if a tv condition is met. You can adapt it to your needs. I built it to work with a check box tv so it simply checks for a value (modx only records check box values, not unchecked). You can set your default TV/chunk or specify them in the call &tv=`` &chunk=``
        <?php
        // set the variables
        $chunk = isset( $chunk ) ? $chunk : "defaultChunk";
        $tv = isset( $tv ) ? $tv : "defaultTV"; 
        
        // get chunk and tv values
        $chunk_value = $modx -> getChunk( $chunk );
        $tv_value = $modx -> getTemplateVarOutput( $tv);
        
        // check if tv and chunk have been selected
        if ($tv_value[$tv] != "" || $chunk != "") { 
        		$output = $chunk_value; 
        	} else {
        		$output = "";
        	}
        
        return $output;
        ?>
          [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

          Something is happening here, but you don&#39;t know what it is.
          Do you, Mr. Jones? - [bob dylan]
          • 26179
          • 21 Posts
          Thanks all!

          dev_cw,
          I tried your solution (I think it’s easier and faster)
          All it work, but my chunk contents a snippet and it’s not executed, but wrote down sad
          What you suggest ??
            • 26179
            • 21 Posts
            SOLVED !!!!


            Instead of using:
            $output = $chunk_value; 


            I call directly the snippet + some additional parts

            $output = '<hr><div id="commenti">';
            $params['customfields'] = 'name,email';
            $params['subscribe'] = '1';
            $params['pagination'] = '4';
            $params['badwords'] = '{{parolacce}}';
            $params['canmoderate'] = 'Site Admins';
            $params['captcha'] = '2';
            $params['moderated'] = '1';
            $output .= $modx->runSnippet('Jot', $params);
            $output .= '</div>'; 
            


            and it perfectly works!
            grin
              • 23491 ☆ A M B ☆
              • 1,056 Posts
              Quote from: Sara75 at Sep 04, 2008, 04:39 AM

              Thanks all!

              dev_cw,
              I tried your solution (I think it’s easier and faster)
              All it work, but my chunk contents a snippet and it’s not executed, but wrote down sad
              What you suggest ??

              Sara, if your snippet call is [!snippet!], try running it as [[snippet]] when within the chunk. Glad to see you found a solution that worked for you, btw. wink
                Mike Reid - www.pixelchutes.com
                MODx Ambassador / Contributor
                [Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
                ________________________________
                Where every pixel matters.