We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 16681
    • 62 Posts
    This is an auto-generated topic for SIMPLX Widgeteer 0.5-Beta1 by larscwallin.

    Brief Description:

    New version for Revolution, packaged using PacMan. This is my first Revo package and i hope it works (since i have not tried the transport zip myself).
    If you have any issues installing let me know smiley

    Ciao,
    Lars
      Keep it SIMPLX
      • 16681
      • 62 Posts
      Updated instructions

      Description

      Integrate and Mashup the easy way!

      More and more data on the web, as well as on local systems, are available through descriptive formats as xml and json. Such formats can be used to display data from other systems, such as news updates etc.

      Displaying, or rendering, information in a json feed takes parsing of the json data, extracting relevant data and inserting this data into some kind of template document. This is where the Widgeteer steps in and keeps it SIMPLX!

      The Widgeteer takes a very pleasent Modxish way to accomplish this: chunkMatching.

      Consider the following json string:

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

      {
      "source":"modx",
      "result":[
      {"id":"1","type":"document","pagetitle":"JSON Test","description":"Simple demo of json"},
      {"id":"2","type":"document","pagetitle":"JSON Test 2","description":"Simple demo of json 2"}
      ]
      }

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

      This is a very simplified json representing two pages in ModX.

      First of all, as soon as you spot the char "{" its the start of a new json object representation. Consequently "}" finishes an object.

      The first object in the json string above only has two attributes: "source", "result". "source" has the value "modx". The "result" attribute though is followed by "[". This sign represents the start of an array of json objects, in this case ModX documents. Widgeteer calls the "result" attribute "dataSetRoot", in other words the element which holds the array of data we want to render.

      Instructions

      The Widgeteer Snippet call:

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

      [!SIMPLX_Widgeteer?
      dataSet=`{"source":"modx","result":[{"id":"1","type":"document","pagetitle":"JSON Test","description":"Simple demo of json"},{"id":"2","type":"document","pagetitle":"JSON Test 2","description":"Simple demo of json 2"}]}`
      &dataSetRoot=`result`
      &useChunkMatching=true
      &chunkMatchingSelector=`type`
      &chunkPrefix=`test.`!]

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

      The above call tells the Snippet:

      1. to load a dataSet of json data.
      2. to use the "result" element as root,
      3. to automatically match json objects to Chunks,
      4. which field in the json object to match Chunks with,
      5. if we use a prefix in the Chunk name ("test.document" in this example)

      The Snippet will now parse through the "result" array and for each object in the array it will try to find a matching ModX Chunk using the chunkPrefix + chunkMatchingSelector. If it finds a matching Chunk it will take the whole json object and replace the placeholders ([[+field_name]]) with the corresponding fields. A matching Chunk (named "test.document") for the above call could look like this:

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

      <div>
      <p>
      <strong>+pagetitle</strong>
      </p>
      <p>
      [[+desription]]
      <a href="?id=[[+id]]">Read more...</a>
      </p>
      </div>

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

      The Widgeteer can load data from,

      1. a static data set, like in the previous example
      2. a Snippet or a Chunk
      3. an url to any valid json feed (using the dataSourceUrl parameter)

      The parameters:


      • "dataSourceUrl" - An url to any valid json source (uses CURL)
      • "dataSet" - If no dataSourceUrl is specified a json string is expected here
      • "useChunkMatching" - true/false decides if Widgeteer should try to match Chunks
      • "chunkMatchingSelector" - If the useChunkMatching is set to true a json lookup field is expected here
      • "staticChunkName" - If useChunkMatching is set to false, a Chunk name is expected there (will be applied to all json objects)
      • "dataSetRoot" - The json array which holds the objects to parse. Adjust according to json format.
      • "chunkMatchRoot" - true/false, if set to true Widgeteer will try to find a matching Chunk for the dataSetRoot property and wrap results in this.
      • "chunkPrefix" - The prefix alows you to match the same type of json object differently depending on context. Very handy.

      Also

      Included in the Snippet you get a template which includes some examples.
      You also get some sample Chunks which will get you started with templating.

      Dont forget that you can potentially nest Snippet calls in your Chunks in order to parse more complex structures such as Atom feeds etc. I can not account for how this will affect caching henche Snippet performance...

      Have fun!
      /Lars
        Keep it SIMPLX
        • 4172
        • 5,888 Posts
        great idea!
        I will try that soon!
        Didn’t know SIMPLX Widgeteer before now.
        Perhaps we can use it also for multiItemTVs.
          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
          • 16681
          • 62 Posts
          Thnx smiley

          Regarding the multi item tv thing, you can most definitly do this.
          I am in fact in the process of making a new Snippet called SIMPLX DataSets which will help you to easily make sets of
          arbitrary data. This can be used for just about anything, like galleries, news, events, well... pretty much any one-to-many needs smiley

          While i am in the process you can do similar by
          - making a textarea TV with default value of [{"col_1_name":"","col_2_name":"","col_n_name":""}]
          - making a onPreRender... plugin which transforms this textarea to a editable grid using Ext or jQuery dataTables.
          - make sure that the grid data is saved back to the textarea when the grid loses focus.

          Should be easy enough wink

          Ciao,
          Lars
            Keep it SIMPLX
            • 16681
            • 62 Posts
            Sorry for being utterly daft tongue I didnt realize you already made a plug for this wink
            Will check it out.

            Anyway, Widgeteer will help you in any case i think.

            Ciao,
            Lars
              Keep it SIMPLX
              • 16681
              • 62 Posts
              Next Widgeteer version will probably support Smarty templates as well as Chunks. Might also include template preview per property-set in the Snippet view.

              Anybody want XML support?

              Ciao
              Lars
                Keep it SIMPLX
                • 38323
                • 26 Posts
                Lars,

                Thanks fot this great add-on. I'm using it to get and set data from another application via its API. Works great!

                I have an issue installing and using Widgeteer 0.6.5-rc1.

                Installing via Packagemanager doesn't do this:
                In your assets/ folder you will have a new snippets folder in which you will find the xml2json folder/files. This makes it possible to get xml from a Web Service and easily convert it to json.

                There is no folder, and thus no xml2json. I actually really need this part (xml to JSON)

                I have a question:
                My JSON looks like this:
                {
                "0":
                {
                "objecttypename":"contact",
                "firstname":"Lars"
                ...
                },
                "1":
                {
                "objecttypename":"contact",
                "firstname":"Lars"
                ...
                },
                ...
                }

                How to parse these? My dataSetRoot is 0, 1, etc.

                Thanks for your reply!
                  • 16681
                  • 62 Posts
                  Hello Mr smiley
                  I'll look into it asap.
                    Keep it SIMPLX
                    • 38323
                    • 26 Posts
                    Quote from: larscwallin at Dec 10, 2012, 07:02 AM
                    Hello Mr smiley
                    I'll look into it asap.

                    Nice!
                      • 27106
                      • 147 Posts
                      Lars, are there any issues with configuring SIMPLX Widgeteer to process data from an FTP uplaod - i.e. from an XML document that already exists on your server?
                        David Walker
                        Principal, Shorewalker DMS
                        Phone: 03 8899 7790
                        Mobile: 0407 133 020