We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38512
    • 8 Posts
    Hello,

    I'm evaluating different options on how to implement my next project, modX is one of them and I like it very much so far (haven't yet used it in anything) but I'm struggling with this one thing.

    Lots of pages in my site will contain a table with 20+ values. I guessed these should be provided by content creators using TVs but filling in 20 fields in the manager is kind of troubling.
    Content creators have a spreadsheet with all the values so I figured I could export this using some sort of field1=value1;field2=value2; format, have them paste that into ImportTV and parse this value to set all the other TVs (Field1TV, Field2TV, etc.).
    If I only needed to present those values in a template, I would go with that single ImportTV and parse that through a snippet and output to a chunk but I need these other TVs because I need to be able to query for their values for search or sorting features.

    How do I do that?

    What I tried so far:

    1. Bindings
    In Field1 TV Input Options Value:
    @EVAL $modx->getTVValue("ImportTV") . "concat";

    Didn't work at all.

    2. Using a snippet in the template - sort of works but there are caching problems:
    $modx->resource->setTVValue("Field1", $modx->resource->getTVValue("ImportTV") . " concat");


    Even if I run the snippet with [[!parseTVs]], value of Field1 does not change on the website when I edit the resource and change ImportTV. I need to clear caches or maybe edit the snippet to make this work.

    I don't know if it's the best approach, maybe there is a better one. If I made this myself, I would just use a database table with all the fields I need as columns, parsed the Import field and saved it to the db upon clicking "Save" on the document, cleared the cache and that's it.

    Any suggestions? [ed. note: pooerh last edited this post 14 years, 8 months ago.]
      • 38512
      • 8 Posts
      By hacking around, I found how to refresh the cache in php so my snippet looks like this:
      $modx->resource->setTVValue('Field1', $modx->resource->getTVValue('ImportTV') . "concat");
      $contexts = array($modx->resource->get('context_key'));
      $modx->cacheManager->refresh(array('resource' => array('contexts' => $contexts)));


      This updates the Field1 as rendered in the template after two page refreshes.Nevertheless, maybe there is a better way to do what I'm trying to do, so any suggestions are welcome smiley