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?
ExpressionEngine® Answers is a question and answer site for administrators, end users, developers and designers for ExpressionEngine® CMS. It only takes a minute to sign up.
Sign up to join this communityI'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?
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.
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}
{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, 2015 at 1:26