We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32396
    • 56 Posts
    Need Help.

    Evo 1.0.2

    I have TV with:

    Template Variable Name: tools
    Input Type: CheckBox
    Input Option Values: Option1||Option2||Option3||Option4
    Widget: Delimeter List ","

    With Ditto call I output the list of documents where this TV is used and in Ditto template [+tools+] outputs:

    <div>1. Option1,Option4</div>
    <div>2. Option2,Option3,Option4</div>
    ...


    How can I output each value of TV [*tools*] in this way:
    <div>1. <span class="opt1">Option1</span>,<span class="opt4">Option4</span></div>
    <div>2. <span class="opt2">Option2</span>,<span class="opt3">Option3</span>,<span class="opt4">Option4</span></div>
    ...


    Thanks!
      Using: MODx Evo 1.0.6 / Revo 2.2.5
      • 26931
      • 2,314 Posts
      hi there,

      this should work ... although the code is probably ugly ( so if anyone feels like cleaning it up, go ahead smiley )
      create a new snippet (call it whatever you want) and place it in your template:
      <?php
      $output="";
      $id=$modx->documentIdentifier;
      $document_tvs=$modx->getTemplateVarOutput(true, $id);
      $TVvalue=$document_tvs['tools'];
      $TVarray=explode( ",", $TVvalue );
      
      $tagnum=count($TVarray);
      $lasttag=($tagnum)-1;
      
      for ($i=0; $i<=($tagnum)-2; $i++) {
      		$classnum=($i)+1;
      		$firsttags .= "<option class=\"opt$classnum\">"."$TVarray[$i]".","." "."</otion>";
      	}
      
      $output="$firsttags" . "<option class=\"opt$tagnum\">"."$TVarray[$lasttag]"."</option>";
      return $output;
      ?>

      initially i wrote it because i couldn’t get a space after the comma of that delimeted list

      guess i could make a PHX modifier out of it too
        • 32396
        • 56 Posts
        2 sharkbait,

        Thanks for help, but if I get it right, with your snippet I can’t specify a className for each of Checkbox Option.

        For example, if in the some document TV [*tools*] checked values are Option2 and Option4 using your code will add classes: "opt1" and "opt2".

        But I need to be like this:

        <div>2. <span class="opt2">Option2</span>, <span class="opt4">Option4</span></div>


          Using: MODx Evo 1.0.6 / Revo 2.2.5
          • 20413
          • 2,877 Posts
          @sharkbait You rock! smiley

          The widget: "HTML Generic Tag" would not give a different class number.

          @Wild Striker Why don’t you want numbers in order based on what shows up?
            @hawproductions | http://mrhaw.com/

            Infograph: MODX Advanced Install in 7 steps:
            http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

            Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
            http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
            • 26931
            • 2,314 Posts
            The widget: "HTML Generic Tag" would not give a different class number.
            no smiley
              • 26931
              • 2,314 Posts
              Thanks for help, but if I get it right, with your snippet I can’t specify a className for each of Checkbox Option.

              For example, if in the some document TV [*tools*] checked values are Option2 and Option4 using your code will add classes: "opt1" and "opt2".
              ah, okay ... hmm *pondering*
                • 32396
                • 56 Posts
                Quote from: mrhaw at Feb 21, 2010, 01:37 PM

                @Wild Striker Why don’t you want numbers in order based on what shows up?

                Because every Option*X will have an different Image Icon...
                  Using: MODx Evo 1.0.6 / Revo 2.2.5
                  • 20413
                  • 2,877 Posts
                    @hawproductions | http://mrhaw.com/

                    Infograph: MODX Advanced Install in 7 steps:
                    http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

                    Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
                    http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
                    • 32396
                    • 56 Posts
                    Yeah!!! I did it ))

                    May be it’s not very optimized but for me it’s working.

                    <?php
                    // Use snippet [[UsedTools?id=[+id+] ]] in Ditto call template
                    // TV values: Flash||HTML||CSS||JS||PHP||MySQL
                    
                    $output = "";
                    $document_tvs = $modx->getTemplateVarOutput(true, $id);
                    $TVvalue = $document_tvs['tools'];
                    $TVarray = explode(",",$TVvalue);
                    
                    	foreach ($TVarray as $val) {
                    		switch ($val) {
                    			case "Flash":
                    				$output .= "<span class=\"ico-flash\">".$val."</span>";break;
                    			case "HTML":
                    				$output .= "<span class=\"ico-html\">".$val."</span>";break;
                    			case "CSS":
                    				$output .= "<span class=\"ico-css\">".$val."</span>";break;
                    			case "JS":
                    				$output .= "<span class=\"ico-js\">".$val."</span>";break;
                    			case "PHP":
                    				$output .= "<span class=\"ico-php\">".$val."</span>";break;
                    			case "MySQL":
                    				$output .= "<span class=\"ico-mysql\">".$val."</span>";break;
                    		}
                    	}
                    
                    return $output;
                    ?>


                    P.S. Thanks for helping
                      Using: MODx Evo 1.0.6 / Revo 2.2.5
                      • 26931
                      • 2,314 Posts
                      Yeah!!! I did it ))
                      great! smiley

                      ...thought it needs to be dynamic ( e.g. automatically assigning a new class if you add another TV value / without editing the snippet )