0

I'm trying to pass {ip_address} to a module, which isn't working:

{exp:rest url="http://domain.com/{ip_address}" verb="get" format="json"}

{/exp:rest}

The {ip_address} is getting interpreted as a string. How do I make this work?

1
  • Did you try adding parse="inward" as a parameter? Apr 7 '15 at 17:03
2

One really simple way to get around parse order is just to use an embed.

{embed="embeds/_rest" ip_address="{ip_address}"}

Then in your embedded template (embeds/_rest):

{exp:rest url="http://domain.com/{embed:ip_address}" verb="get" format="json"}

{/exp:rest}

Embeds get a bad rap performance-wise, but as long as you aren't using them excessively or inside a foreach loop like a channel:entries tag pair then in my opinion they're a handy way to get around parse order.

1
  • Good call on the embed, I though he was building the module. Apr 7 '15 at 15:11
0

User defined global variables are parsed at the very end, which you can see in Low's parse order sheet which comes in handy.

However you can get the config variables in the backend with php.

ee()->config->item('ip_address');

UPDATE

Alex's solution should work as well, but in case you don't want to use the embed you could also allow php and set it to parse on input, and replace {url_title} with the php variable. I would just use the embed method.

{exp:rest 
    url="http://domain.com/<?php echo ee()->config->item('ip_address'); ?>" 
    verb="get" 
    format="json"
}

{/exp:rest}
1
  • 1
    I need to be able to pass the {ip_address} to {exp:rest} (and not have to modify the module to get the ip address). Is there a way I could use Stash to get around this problem? Apr 7 '15 at 1:26

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.