<![CDATA[ I need to have SimpleSearch to search Template Variables, but this is not working... - My Forums]]> https://forums.modx.com/thread/?thread=99098 <![CDATA[I need to have SimpleSearch to search Template Variables, but this is not working...]]> https://forums.modx.com/thread/99098/i-need-to-have-simplesearch-to-search-template-variables-but-this-is-not-working?page=2#dis-post-535911
How can I make Simple Search also search Template Variables?
[[!SimpleSearch?
&tpl=`search_form_row_tpl`
&perPage=`6`
&includeTVs=`1`
&processTVs=`1`
&containerTpl=`search_form_container_tpl`
&pageTpl=`search_form_pageTpl`
&pageNextTpl=`search_form_pageNextTpl`
&pagePrevTpl=`search_form_pagePrevTpl`
&currentPageTpl=`search_form_currentPageTpl`
&pagingSeparator=``
]]
]]>
ThaClown Dec 15, 2015, 03:51 AM https://forums.modx.com/thread/99098/i-need-to-have-simplesearch-to-search-template-variables-but-this-is-not-working?page=2#dis-post-535911
<![CDATA[Re: I need to have SimpleSearch to search Template Variables, but this is not working...]]> https://forums.modx.com/thread/99098/i-need-to-have-simplesearch-to-search-template-variables-but-this-is-not-working?page=2#dis-post-552687 Bruno17 Jul 21, 2017, 05:26 AM https://forums.modx.com/thread/99098/i-need-to-have-simplesearch-to-search-template-variables-but-this-is-not-working?page=2#dis-post-552687 <![CDATA[Re: I need to have SimpleSearch to search Template Variables, but this is not working...]]> https://forums.modx.com/thread/99098/i-need-to-have-simplesearch-to-search-template-variables-but-this-is-not-working?page=2#dis-post-552686 atype Jul 21, 2017, 03:20 AM https://forums.modx.com/thread/99098/i-need-to-have-simplesearch-to-search-template-variables-but-this-is-not-working?page=2#dis-post-552686 <![CDATA[Re: I need to have SimpleSearch to search Template Variables, but this is not working...]]> https://forums.modx.com/thread/99098/i-need-to-have-simplesearch-to-search-template-variables-but-this-is-not-working?page=2#dis-post-548650 Quote from: Bruno17 at Dec 15, 2015, 06:33 AM
this is one, which I did this days.
It is runnung on all resources with given migxtv_templates (3 and 7)
It stores all configured Text-fields of configured MIGX-TVs into a target_tv.
The target_tv could be at the same resource (if the template matches the given template)
or into a child-resource, which matches the given template.
This was for a special setup, where some of the MIGX-TVs was not listed at the same resource, but at a child-resource. Normally this option isn't needed.

It reads also nested MIGX - TVs, example here, the field 'downloads' with type 'migx' in the migxtv3.

<!--?php

$migxtv_templates = '3,7';
$config = '[
{"tvname":"migxtv","template":"3","target_tv":"searchMigxData","fields":[
    {"field":"headline"},
    {"field":"text"}
]},
{"tvname":"migxtv","template":"7","target_tv":"searchMigxData","fields":[
    {"field":"headline"},
    {"field":"text"}
]},
{"tvname":"othermigxtv","template":"4","target_tv":"searchMigxData","fields":[
    {"field":"headline"},
    {"field":"text"}
]},
{"tvname":"migxtv3","template":"5","target_tv":"searchMigxData","fields":[
    {"field":"headline"},
    {"field":"text"},
    {"field":"headline_bundle"},
    {"field":"downloads","type":"migx","fields":[
        {"field":"title1"},
        {"field":"title2"},
        {"field":"text"}
    ]}
]}
]';

function jsonFieldsToArray($items, $fields) {
    global $modx;
    
    $output = array();
    if (!is_array($items)) {
        $items = $modx--->fromJson($items);
    }
    if (is_array($items)) {
        foreach ($items as $item) {
            foreach ($fields as $field) {
                $fieldname = $modx->getOption('field', $field, '');
                $type = $modx->getOption('type', $field, '');
                if (isset($item[$fieldname])) {
                    if ($type == 'migx') {
                        $subitems = $item[$fieldname];
                        $subfields = $modx->getOption('fields', $field, '');
                        $suboutput = jsonFieldsToArray($subitems,$subfields);
                        $output = array_merge($output,$suboutput);  
                    } else {
                        $output[] = $item[$fieldname];
                    }
                }
            }
        }
    }
    return $output;
}


$migxtv_templates = explode(',', $migxtv_templates);

$resource_template = $resource->get('template');
if (in_array($resource_template, $migxtv_templates)) {

    $config = $modx->fromJson($config);
    foreach ($config as $cfg) {
        $tvname = $modx->getOption('tvname', $cfg, '');
        $template = $modx->getOption('template', $cfg, '');
        $fields = $modx->getOption('fields', $cfg, '');
        $target_tv = $modx->getOption('target_tv', $cfg, '');
        $items = $resource->getTVValue($tvname);
        $values = jsonFieldsToArray($items, $fields);
        if ($template == $resource_template){
            //has the template itself - we save to that resource
            $resource->setTVValue($target_tv,implode("\n\n",$values));
            
        }elseif ($target_resource = $modx->getObject('modResource',array('template'=>$template,'parent'=>$resource->get('id')))){
            //otherwise search child-resource with that template
            $target_resource->setTVValue($target_tv,implode("\n\n",$values)); 
        }
    }
    
}

This looks like what I would need but not sure on how and what to do from here, multiple site and migxmultilang... search is only working on one language, retuning nothing found in other language sad]]>
Egam Feb 09, 2017, 05:41 PM https://forums.modx.com/thread/99098/i-need-to-have-simplesearch-to-search-template-variables-but-this-is-not-working?page=2#dis-post-548650
<![CDATA[Re: I need to have SimpleSearch to search Template Variables, but this is not working...]]> https://forums.modx.com/thread/99098/i-need-to-have-simplesearch-to-search-template-variables-but-this-is-not-working#dis-post-535933 ThaClown Dec 15, 2015, 07:00 AM https://forums.modx.com/thread/99098/i-need-to-have-simplesearch-to-search-template-variables-but-this-is-not-working#dis-post-535933 <![CDATA[Re: I need to have SimpleSearch to search Template Variables, but this is not working...]]> https://forums.modx.com/thread/99098/i-need-to-have-simplesearch-to-search-template-variables-but-this-is-not-working#dis-post-535930
Damn will have to buy you a beer again... **mumbling whilst clicking the sponsor link**
]]>
ThaClown Dec 15, 2015, 06:37 AM https://forums.modx.com/thread/99098/i-need-to-have-simplesearch-to-search-template-variables-but-this-is-not-working#dis-post-535930
<![CDATA[Re: I need to have SimpleSearch to search Template Variables, but this is not working... (Best Answer)]]> https://forums.modx.com/thread/99098/i-need-to-have-simplesearch-to-search-template-variables-but-this-is-not-working#dis-post-535928 It is runnung on all resources with given migxtv_templates (3 and 7)
It stores all configured Text-fields of configured MIGX-TVs into a target_tv.
The target_tv could be at the same resource (if the template matches the given template)
or into a child-resource, which matches the given template.
This was for a special setup, where some of the MIGX-TVs was not listed at the same resource, but at a child-resource. Normally this option isn't needed.

It reads also nested MIGX - TVs, example here, the field 'downloads' with type 'migx' in the migxtv3.

<?php

$migxtv_templates = '3,7';
$config = '[
{"tvname":"migxtv","template":"3","target_tv":"searchMigxData","fields":[
    {"field":"headline"},
    {"field":"text"}
]},
{"tvname":"migxtv","template":"7","target_tv":"searchMigxData","fields":[
    {"field":"headline"},
    {"field":"text"}
]},
{"tvname":"othermigxtv","template":"4","target_tv":"searchMigxData","fields":[
    {"field":"headline"},
    {"field":"text"}
]},
{"tvname":"migxtv3","template":"5","target_tv":"searchMigxData","fields":[
    {"field":"headline"},
    {"field":"text"},
    {"field":"headline_bundle"},
    {"field":"downloads","type":"migx","fields":[
        {"field":"title1"},
        {"field":"title2"},
        {"field":"text"}
    ]}
]}
]';

function jsonFieldsToArray($items, $fields) {
    global $modx;
    
    $output = array();
    if (!is_array($items)) {
        $items = $modx->fromJson($items);
    }
    if (is_array($items)) {
        foreach ($items as $item) {
            foreach ($fields as $field) {
                $fieldname = $modx->getOption('field', $field, '');
                $type = $modx->getOption('type', $field, '');
                if (isset($item[$fieldname])) {
                    if ($type == 'migx') {
                        $subitems = $item[$fieldname];
                        $subfields = $modx->getOption('fields', $field, '');
                        $suboutput = jsonFieldsToArray($subitems,$subfields);
                        $output = array_merge($output,$suboutput);  
                    } else {
                        $output[] = $item[$fieldname];
                    }
                }
            }
        }
    }
    return $output;
}


$migxtv_templates = explode(',', $migxtv_templates);

$resource_template = $resource->get('template');
if (in_array($resource_template, $migxtv_templates)) {

    $config = $modx->fromJson($config);
    foreach ($config as $cfg) {
        $tvname = $modx->getOption('tvname', $cfg, '');
        $template = $modx->getOption('template', $cfg, '');
        $fields = $modx->getOption('fields', $cfg, '');
        $target_tv = $modx->getOption('target_tv', $cfg, '');
        $items = $resource->getTVValue($tvname);
        $values = jsonFieldsToArray($items, $fields);
        if ($template == $resource_template){
            //has the template itself - we save to that resource
            $resource->setTVValue($target_tv,implode("\n\n",$values));
            
        }elseif ($target_resource = $modx->getObject('modResource',array('template'=>$template,'parent'=>$resource->get('id')))){
            //otherwise search child-resource with that template
            $target_resource->setTVValue($target_tv,implode("\n\n",$values)); 
        }
    }
    
}
]]>
Bruno17 Dec 15, 2015, 06:33 AM https://forums.modx.com/thread/99098/i-need-to-have-simplesearch-to-search-template-variables-but-this-is-not-working#dis-post-535928
<![CDATA[Re: I need to have SimpleSearch to search Template Variables, but this is not working...]]> https://forums.modx.com/thread/99098/i-need-to-have-simplesearch-to-search-template-variables-but-this-is-not-working#dis-post-535925 ThaClown Dec 15, 2015, 06:16 AM https://forums.modx.com/thread/99098/i-need-to-have-simplesearch-to-search-template-variables-but-this-is-not-working#dis-post-535925 <![CDATA[Re: I need to have SimpleSearch to search Template Variables, but this is not working...]]> https://forums.modx.com/thread/99098/i-need-to-have-simplesearch-to-search-template-variables-but-this-is-not-working#dis-post-535923 with a plugin, that runs at OnDocFormSave.]]> Bruno17 Dec 15, 2015, 06:11 AM https://forums.modx.com/thread/99098/i-need-to-have-simplesearch-to-search-template-variables-but-this-is-not-working#dis-post-535923 <![CDATA[Re: I need to have SimpleSearch to search Template Variables, but this is not working...]]> https://forums.modx.com/thread/99098/i-need-to-have-simplesearch-to-search-template-variables-but-this-is-not-working#dis-post-535922 ThaClown Dec 15, 2015, 05:48 AM https://forums.modx.com/thread/99098/i-need-to-have-simplesearch-to-search-template-variables-but-this-is-not-working#dis-post-535922