Get's location information based on user's IP
This plugin requires Craft CMS 3.0.0-beta.23 or later.
To install the plugin, follow these instructions.
-
Open your terminal and go to your Craft project:
cd /path/to/project -
Then tell Composer to load the plugin:
composer require PrimitiveSocial/ip-country -
In the Control Panel, go to Settings → Plugins and click the “Install” button for IP Country.
This get's the user's location data based on their IP address for use in Twig templates.
No need! Comes ready to go out of the box.
For testing locally, you will need to test at a remote server. Running this locally will return your IP address (127.0.0.1), which will not give any data.
A simple way to get around this is to test via Ngrok;
This sets the IP variable
{% set ip = craft.ipcountry.get %}
Then, you can check to see if the person is in North America
{% if ip and ip.continent_code == 'NA' %}
<p>What up North America!</p>
{% endif %}
Check the city
{% if ip and ip.city == 'Lubbock' %}
<p>Lubbock is the best</p>
{% endif %}
Check the state
{% if ip and ip.state == 'Texas' %}
<p>Texas is awesome!</p>
{% endif %}
Check the country
{% if ip and ip.country == 'Canada' %}
<p>Hooray for Canada!</p>
{% endif %}
Some things to do, and ideas for potential features:
- Release it
Brought to you by Primitive Social
