# Multiple autotags within single NewsPublisher Form?

**URL:** <https://community.modx.com/t/multiple-autotags-within-single-newspublisher-form/4847>\
**Category:** Extras\
**Created:** [January 16, 2022, 2:03am UTC](https://community.modx.com/t/multiple-autotags-within-single-newspublisher-form/4847 "2022-01-16T02:03:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wpicotte](https://community.modx.com/user_avatar/community.modx.com/wpicotte/32/855_2.png) [@wpicotte](https://community.modx.com/u/wpicotte)\
**Post date:** [January 16, 2022, 2:03am UTC](https://community.modx.com/t/multiple-autotags-within-single-newspublisher-form/4847/1 "2022-01-16T02:03:16Z")

</div>

Auto-tags in NewsPublisher work so long as a single autotag is used within a given NewsPublisher form.

A case statement added to newspublisher.class.php assigns a tpl to any autotag TV included in the NewsPublisher call:

```auto
case 'autotag':
 $formTpl .= $this->_displaySimple($name, 'TagOuterTpl', '');
break;

```

I seek a method whereby multiple autotag template variables can be ‘shown’ in the same NewsPublisher form. Is it possible to specify TV names in autotag case statements, enabling assignment of unique tpls per named autotag TV?

For reference, my TagOuterTpl looks like:

```auto
<div id="np-[[+npx.fieldName]]-container" class="np-text custom-container">
   [[+np.error_[[+npx.fieldName]]]]
   <div class="tag-input-wrap">
      <label class="fieldlabel" for="np-[[+npx.fieldName]]" [[+npx.readonly]] title="[[+npx.help]]">[[+npx.caption]]: </label>
      <input contenteditable name="[[+npx.fieldName]]" class="text tag-input" id="np-[[+npx.fieldName]]" type="text" value="[[+np.[[+npx.fieldName]]]]" maxlength="[[+npx.maxlength]]" />
  </div>
[[*template:is=`5`:or:is=`9`:then=`[[$tag-form-tpl-chart]]`]]
[[*template:is=`15`:then=`[[$tag-form-tpl-ticker]]`]]
[[*template:is=`17`:then=`[[$pf-trigger-form]]`]]

```

The `[[*template]]` tags switch chunks containing `[[taglister]]` calls based on template. Works great for a single autotag per NP form.

For example, `[[$tag-form-tpl_chartTag]]`:

```auto
    <div class="tag-block">
        [[!tagLister? &tv=`chartTag` &parents=`6` &tagKey=`chartTag` &tpl=`npTagTpl` &target=`[[*id]]` &limit=`100` &activeCls=`current` &toPlaceholder=`available-tags`]]
        [[+available-tags:notempty=`<label class="fieldlabel">Existing chart tags:</label>`]]
        [[+available-tags]]
    </div>
</div>
<script>
    function toggleTag(t){
      var val = document.getElementById("np-[[+npx.fieldName]]").value;
      var tags = val ? val.split(',') : [];
      var index = tags.indexOf(t);
      if(index > -1){
        tags.splice(index, 1);
      }else{
        tags.push(t);
      }
      document.getElementById("np-[[+npx.fieldName]]").value = tags.join(',');
    }
</script>
<script>
 $('form').submit(function(e) {
        $('.submit').each(function() {
            var pH = $.trim($(this).val());
            var pHn = pH.replace(/,\s*$/, '');
            $(this).val(pHn);
        });
    });
 $(function() {
    var [[+npx.fieldName]]Tags = [[[!tagLister? &tv=`chartTag` &tpl=`tag-item-alt` &parents=`6` &limit=`100` &outputSeparator=`,`]] ];
    function split( val ) {
      return val.split( /,\s*/ );
    }
    function extractLast( term ) {
      return split( term ).pop();
    }
 
    $( "#np-[[+npx.fieldName]]" )
      // don't navigate away from the field on tab when selecting an item
      .bind( "keydown", function( event ) {
        if ( event.keyCode === $.ui.keyCode.TAB &&
            $( this ).data( "ui-autocomplete" ).menu.active ) {
          event.preventDefault();
        }
      })
      .autocomplete({
        minLength: 0,
        source: function( request, response ) {
          // delegate back to autocomplete, but extract the last term
          response( $.ui.autocomplete.filter(
            [[+npx.fieldName]]Tags, extractLast( request.term ) ) );
        },
        focus: function() {
          // prevent value inserted on focus
          return false;
        },
        select: function( event, ui ) {
          var terms = split( this.value );
          // remove the current input
          terms.pop();
          // add the selected item
          terms.push( ui.item.value );
          // add placeholder to get the comma-and-space at the end
          terms.push( "" );
          this.value = terms.join( ", " );
          return false;
        }
    });
});
</script>

```

---

<div class="post-metadata">

**Author:** ![halftrainedharry](https://community.modx.com/user_avatar/community.modx.com/halftrainedharry/32/1063_2.png) [@halftrainedharry](https://community.modx.com/u/halftrainedharry)\
**Post date:** [January 16, 2022, 1:07pm UTC](https://community.modx.com/t/multiple-autotags-within-single-newspublisher-form/4847/2 "2022-01-16T13:07:46Z")

</div>

I suppose you added your custom _case_ for autotags to this _switch statement_ in the code:

> <https://github.com/BobRay/newspublisher/blob/c8cda5a2d82be5979904bbfefbf965f74e9492b1/core/components/newspublisher/model/newspublisher/newspublisher.class.php#L1458>

> [@wpicotte](#):
>
> Is it possible to specify TV names in autotag case statements, enabling assignment of unique tpls per named autotag TV?

The variable **$name** that you use in your code is the name of the TV. So you should be able to do something like this:

```auto
case 'autotag':
	if ($name == 'myAutotag1'){
		$formTpl .= $this->_displaySimple($name, 'TagOuterTpl', '');
	} elseif ($name == 'myAutotag2') {
		$formTpl .= $this->_displaySimple($name, 'OtherTagOuterTpl', '');
	}
	break;

```

---

<div class="post-metadata">

**Author:** ![wpicotte](https://community.modx.com/user_avatar/community.modx.com/wpicotte/32/855_2.png) [@wpicotte](https://community.modx.com/u/wpicotte)\
**Post date:** [January 16, 2022, 5:44pm UTC](https://community.modx.com/t/multiple-autotags-within-single-newspublisher-form/4847/3 "2022-01-16T17:44:00Z")

</div>

> [@halftrainedharry](#):
>
> I suppose you added your custom _case_ for autotags to this _switch statement_ in the code:
> 
> [newspublisher/core/components/newspublisher/model/newspublisher/newspublisher.class.php at c8cda5a2d82be5979904bbfefbf965f74e9492b1 · BobRay/newspublisher · GitHub](https://github.com/BobRay/newspublisher/blob/c8cda5a2d82be5979904bbfefbf965f74e9492b1/core/components/newspublisher/model/newspublisher/newspublisher.class.php#L1458)

Your supposition is correct.
