1

I'm trying to import posts using the Feed Me plugin. I'd like to make a dynamic URL so that I can access the feed from a Cron job or from elsewhere in the CP. It says in the docs that I can use environment variables inside the Feed URL, but it isn't working for me. Am I using them the wrong way?

My Feed URL (not working):

http://some-url.com/{{issueNumber}}

Apart from environment variables, is there some other way to pass variables into Feed Me? The client won't have direct access to the Feed Me plugin and therefore won't be able to manually edit the URL each time.

1
  • Update: I've updated my code so that this is no longer necessary, but I'm leaving the question up in case someone can use it in the future.
    – jtenclay
    Jan 15, 2018 at 19:51

2 Answers 2

2

There's currently no method to parse variables into the feed itself through this, or any means. Typically, we approach this as feeds being third-party, or otherwise non-editable. How would you see utilising issueNumber to work in this scenario?

You can use the concept of aliases in your URL if that helps?

Lastly, you could also make use of the (undocumented) Datatype::EVENT_AFTER_FETCH_FEED event to perform any parsing on the feed once its been fetched?

2
  • It turned out the way I was thinking about this didn't really make sense – I was hoping that I could use another plugin to edit the feed URL before starting it, essentially pulling data from a different URL each time. I ended up handling that bit in the other plugin by making a local copy of the changing file each time so that Feed Me could point to the local version reliably.
    – jtenclay
    May 7, 2018 at 20:46
  • I think using aliases probably would have been a more straightforward way, so I'm definitely going to use that suggestion in the future
    – jtenclay
    May 7, 2018 at 20:47
0

Feed Me supports this but the setting isn't turned on by default.

  1. Create an feed-me.php file under your /config directory
  2. Turn on the parseTwig option using:
<?php

return [
    '*' => [
        'parseTwig' => true
    ]
];
  1. You can now use twig variables in the default value field eg. if issueNumber is a field and the field is being populated by your feed you can set the default to http://some-url.com/{issueNumber}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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