We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37042
    • 384 Posts
    I have a getResources call which outputs odd and even tpls
    &tplOdd=`layer-dark` &tpl=`layer-light`


    All working beautifully until my client has decided that they would like *some* resources to use a completely different tpl.

    I looked at using the
    tpl_N
    to make this happen but my client can'r guarantee that the resource will always be 1st or 25th or in a specific order.

    Any ideas?

    I'd like to make a TV checkbox called "Unique" which my client would check when using creating the resource. And then I'd like my getResources call to encounter this TV has been checked and to bypass
    &tplOdd=`layer-dark` &tpl=`layer-light`
    and instead use my "unique" tpl for that particular resource.

      ...
      • 18373 ☆ A M B ☆
      • 3,141 Posts
      Easiest solution that comes to mind is using output filters (or the If snippet if you so prefer) to check that TV value in the actual tpl.

      [[+tv.unique:notempty=`
        <div class="unique">[[+pagetitle]]</div>
      `:default=`
        <div class="plainold">[[+pagetitle]]</div>
      `]]
        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
        • 42046
        • 436 Posts
        You could also use conditional templates in the getResources call

          &tplCondition=`field/TV`
          &conditionalTpls=`{"1":"tplA","2":"tplB","3":"tplC"}`
          &tpl=`defaultTpl`
          • 37042
          • 384 Posts
          Thanks Mark and Dan. Both great suggestions.

          Does getResources really support Dan's suggestion? I can't see it anywhere in the documentation and it's such a great feature.

          &tplCondition=`field/TV`
          &conditionalTpls=`{"1":"tplA","2":"tplB","3":"tplC"}`
          &tpl=`defaultTpl`
            ...
            • 4172
            • 5,888 Posts
            I think it should also be possible to switch the used tpl by listbox-TV (switchTpl) with input-option-values like:
            tplA==[[$tplA]]||tplB==[[$tplB]]


            and put just this TV's placeholder in your tpl:

            [[+switchTpl]]


            does this work?
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 42046
              • 436 Posts
              Quote from: eladnova at Jul 30, 2013, 02:11 PM
              Does getResources really support Dan's suggestion? I can't see it anywhere in the documentation and it's such a great feature.

              &tplCondition=`field/TV`
              &conditionalTpls=`{"1":"tplA","2":"tplB","3":"tplC"}`
              &tpl=`defaultTpl`

              Yes it does, but for some reason it's not on the rtfm.

              It was added in v1.5.0 https://github.com/opengeek/getResources/pull/58
                • 18373 ☆ A M B ☆
                • 3,141 Posts
                Quote from: Bruno17 at Jul 30, 2013, 02:55 PM
                I think it should also be possible to switch the used tpl by listbox-TV (switchTpl) with input-option-values like:
                tplA==[[$tplA]]||tplB==[[$tplB]]


                and put just this TV's placeholder in your tpl:

                [[+switchTpl]]


                does this work?

                I wouldn't advise that. For one it may (and I've seen it do that in older versions) execute the [[$tplA/b]] tags in the options, storing the result of the chunk as the value in the database. Secondly you can get scoping issues where the placeholders are not available in the chunk unless you specifically pass them like [[$tplA? &pagetitle=`[[+pagetitle]]`]].

                Quote from: absent42 at Jul 30, 2013, 11:21 AM
                You could also use conditional templates in the getResources call

                  &tplCondition=`field/TV`
                  &conditionalTpls=`{"1":"tplA","2":"tplB","3":"tplC"}`
                  &tpl=`defaultTpl`

                ^ that looks like a great solution, that needs to be documented tongue
                  Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                  Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
                  • 4172
                  • 5,888 Posts

                  For one it may (and I've seen it do that in older versions) execute the [[$tplA/b]] tags in the options, storing the result of the chunk as the value in the database

                  this would be news for me. Had never issues using this technique.
                  I don't think, tags in input-options are parsed, before showing them in the manager.
                  Can't see anything which would parse the tags in input-options here:
                  <?php
                  /**
                   * @package modx
                   * @subpackage processors.element.tv.renders.mgr.input
                   */
                  class modTemplateVarInputRenderListbox extends modTemplateVarInputRender {
                      public function getTemplate() {
                          return 'element/tv/renders/input/listbox-single.tpl';
                      }
                      public function process($value,array $params = array()) {
                          $options = $this->getInputOptions();
                          $items = array();
                  
                          foreach ($options as $option) {
                              $opt = explode("==",$option);
                              if (!isset($opt[1])) $opt[1] = $opt[0];
                              $items[] = array(
                                  'text' => htmlspecialchars($opt[0],ENT_COMPAT,'UTF-8'),
                                  'value' => htmlspecialchars($opt[1],ENT_COMPAT,'UTF-8'),
                                  'selected' => strcmp($opt[1],$value) == 0,
                              );
                          }
                          $this->setPlaceholder('opts',$items);
                      }
                  }
                  return 'modTemplateVarInputRenderListbox';
                  


                      public function getInputOptions() {
                          return $this->tv->parseInputOptions($this->tv->processBindings($this->tv->get('elements'),$this->modx->resource->get('id')));
                      }
                  


                      public function parseInputOptions($v) {
                          $a = array();
                          if(is_array($v)) return $v;
                          else if(is_resource($v)) {
                              while ($cols = mysql_fetch_row($v)) $a[] = $cols;
                          } else if (is_object($v)) {
                              $a = $v->fetchAll(PDO::FETCH_ASSOC);
                          }
                          else $a = explode("||", $v);
                          return $a;
                      }
                  




                  Secondly you can get scoping issues where the placeholders are not available in the chunk unless you specifically pass them like [[$tplA? &pagetitle=`[[+pagetitle]]`]].

                  I think [[$tplA]] in a tpl does work
                  the parser replaces the chunk-tag in the first loop, in the next loop it replaces the resulting getResources-placeholders, if I'm not wrong.
                  I know, this is working in bloX-tpls

                    -------------------------------

                    you can buy me a beer, if you like MIGX

                    http://webcmsolutions.de/migx.html

                    Thanks!
                    • 18373 ☆ A M B ☆
                    • 3,141 Posts
                    I never researched the exact reason it ended up storing the contents of the chunks as template variable contents, but it has definitely caused issues for me before. Either way, the getResources tplCondition is a superior solution.
                      Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                      Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
                      • 28042 ☆ A M B ☆
                      • 24,524 Posts
                      Hm. I wonder if pdoResources has an even better way of handling it.
                        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