0

I have created a module which using curl retrieves and parses data from an external source. I have adapted the code from channel:entries so it outputs the correct values. The method handles the tags and chunks in the same way as it would a category.

{exp:sh_dictionary:translate_result dictionary="wordreference"}

    {additional}
        {exp:stash:append_list name="additional_{count}"}
            {stash:sense}{sense}{/stash:sense}
            {stash:pos}{POS}{/stash:pos}
            {stash:translation}{translation}{/stash:translation}
        {/exp:stash:append_list}
    {/additional}

    {compound}
        {exp:stash:append_list name="compound_{count}"}
            {stash:sense}{sense}{/stash:sense}
            {stash:pos}{POS}{/stash:pos}
            {stash:translation}{translation}{/stash:translation}
        {/exp:stash:append_list}
    {/compound}

{/exp:sh_dictionary:translate_result}

The problem is if I have just the {additional} chunk I get the result I want. And similarly if I just include the {compound} chunk. But if I include them both I get nothing.

Do I need to clear something before setting up a new list? or maybe it is the way my module parses the data. If I wrap each chunk in its own {exp:sh_dictionary:translate_result} it solves the problem but this doesn't feel right as I would need to cache the original curl results.

Thanks

1 Answer 1

1

Before Stash gets to do anything, your custom tag should return something like this:

    {exp:stash:append_list name="additional_1"}
        {stash:sense}sense1{/stash:sense}
        {stash:pos}pos1{/stash:pos}
        {stash:translation}translation1{/stash:translation}
    {/exp:stash:append_list}

    {exp:stash:append_list name="additional_1"}
        {stash:sense}sense2{/stash:sense}
        {stash:pos}pos2{/stash:pos}
        {stash:translation}translation2{/stash:translation}
    {/exp:stash:append_list}

    {exp:stash:append_list name="additional_1"}
        {stash:sense}sense3{/stash:sense}
        {stash:pos}pos3{/stash:pos}
        {stash:translation}translation3{/stash:translation}
    {/exp:stash:append_list}

    {exp:stash:append_list name="compound_1"}
        {stash:sense}sense1{/stash:sense}
        {stash:pos}POS1{/stash:pos}
        {stash:translation}translation1{/stash:translation}
    {/exp:stash:append_list}

    {exp:stash:append_list name="compound_1"}
        {stash:sense}sense2{/stash:sense}
        {stash:pos}POS2{/stash:pos}
        {stash:translation}translation2{/stash:translation}
    {/exp:stash:append_list}

    {exp:stash:append_list name="compound_1"}
        {stash:sense}sense3{/stash:sense}
        {stash:pos}POS3{/stash:pos}
        {stash:translation}translation3{/stash:translation}
    {/exp:stash:append_list}

If you turn on template debugging it will tell you what tags the parser is parsing. Most likely your module isn't properly parsing your two variable pairs and only returning the tagdata for one of the pairs.

In any case, since you are using a custom module, why not just set the list directly from the arrays using Stash's API?

See: https://github.com/croxton/Stash/wiki/Using-stash-methods-in-your-own-add-ons#set-a-list

1
  • Thanks Mark, I went with the API method which worked a treat. Oct 19, 2014 at 12:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.