TV output that populates another TV's list

I’m trying to make a TV that looks something like this:

Category
Item - Percentage

Where each category will have multiple items. But I want the option to have multiple categories too. The catch is that I won’t know how many categories I’ll need until later. So I’d like to have one TV that defines the categories and another TV that creates a list to select from based on the category TV and then I’ll assign items to each of those.

I know I could manually create a dropdown field in MIGX and just add them there for each category, but I’d like to make this dynamic if I can.

Is this even possible to do? Or is there a better way to achieve this?

Thanks

You can fill a dropdown dynamically with the values from a MIGX TV if you put code like this into the field ‘Input Option Values’.

@EVAL return "--- Choose Category ---==||".$modx->runSnippet('getImageList',array('tpl'=>'@CODE:[[+categoryName]]==[[+MIGX_id]]','outputSeparator'=>'||','tvname'=>'categories','docid'=>'10'));
1 Like

does the docid matter? Where did the 10 come from? Or is that the resource id?

Yes, that is just the resource id. You can probably omit it, if the 2 MIGX TVs are defined on the same page.

This worked amazingly! I haven’t tried building this as output just yet, but the TVs are perfect. I was just wondering if there was a way to force the new listbox to sort the content alphabetically? I tried editing the end of the EVAL code like this, adding a sortby and sortdir to the array:

"@EVAL return '--- Choose Category ---==||'.$modx->runSnippet('getImageList',array('tpl'=>'@CODE:[[+expCategory]]==[[+MIGX_id]]','outputSeparator'=>'||','tvname'=>'experienceCategory','sortby'=>'[[+expCategory]]','sortdir'=>'ASC'));"

Unfortunately, it didn’t work. I can always sort the original list manually and save it, but I’m wondering if it’s even doable?

thanks!

It’s definitely doable. Try this:

@EVAL return '--- Choose Category ---==||'.$modx->runSnippet('getImageList',array('tpl'=>'@CODE:[[+expCategory]]==[[+MIGX_id]]','outputSeparator'=>'||','tvname'=>'experienceCategory','sort'=>'[{"sortby":"expCategory","sortdir":"ASC"}]'));

thanks that was a good idea. But I just got stuck with an infinite loading circle.

So I’m stuck, here’s where I’m at with this: sample

I added this into my main template to generate each category.

[[*experienceList:notempty=`
    <hr class="space" />
    [[getImageList?
        &tvname=`experienceCategory`
        &tpl=`serviceExperience`
    ]]
`]]

In the ‘serviceExperience’ chunk to generate the items within each category and the template of the previous TV.

[[getImageList?
    &tvname=`experienceList`
    &tpl=`serviceExperienceItems`
    &toPlaceholder=`output`
    &totalVar=`content_total`
]]

<h2>[[+expCategory:uppercase]]</h2>
<section class="section-base stat_counter">
    <div class="container" style="grid-template-columns: repeat([[+content_total]], 1fr);">
        [[+output]]
    </div>
</section>

Then, the content of that output placeholder:

<div class="counter counter-horizontal counter-icon">
    [[+itemIcon]]
    <div>
        <h3>[[+itemName]]</h3>
        <span>[[+dynamicCategory]]</span> [[-hide this later]]
        <div class="value">
            <span class="text-md" data-to="[[+itemPercent]]" data-speed="5000">[[+itemPercent]]</span>
            <span>%</span>
        </div>
    </div>
</div>

You can see from the link above that it spits out the same results for each category. Despite each item having a different category applied to them in the list TV.

Where I’m getting stuck at is, how can I cross reference dynamicCategory from one TV with expCategory from the previous chunk? I would think that it would be an IF/ELSE statement of some kind. Whereas, if [[+dynamicCategory:eq=‘expCategory’:then=‘display’:else=‘ignore’]].

Does this make any sense?

In your chunk ‘serviceExperience’ you probably have to define a &where-property to filter the data. Something like:

[[getImageList?
	&tvname=`experienceList`
	&tpl=`serviceExperienceItems`
	&toPlaceholder=`output`
	&totalVar=`content_total`
	&where=`{"dynamicCategory":"[[+MIGX_id]]"}`
]]
...