Take the 2-minute tour ×
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It's 100% free, no registration required.

I need to change the content of a static block in magento for visitors from some special countries.

This is the JavaScript embedded into the Magento:

<script src="http://j.maxmind.com/app/country.js" charset="ISO-8859-1"></script>

I use the following code in my static block :

if (geoip_country_code() == 'GB') 
    {
      alert("Hello, you are in Great Britain");
    }

But when i save this static block, magento changes it to this:

<p>if (geoip_country_code() == 'GB') { alert("Hello, you are in Great Britain"); }</p>

??!!

What should i do to determine the GeoIP of the visitors and change the Content to be shown in an static block?

share|improve this question

3 Answers 3

Here are two alternative approaches for you:

  1. You can put your JS logic into external JS file and attach it to CMS page using layout update at the "Design" tab. Then depending on you visitors country you can load the content of appropriate CMS block with ajax.
  2. I can recommend my GeoIP extension. You can use it to detect visitors country on Magento side and then add a corresponding block to your page:

    $geoIP = Mage::getSingleton('geoip/country');
    
    if ($geoIP->getCountry() == 'gb') {
        // show one block
    } else {
        // show another block
    }
    
share|improve this answer
    
can this be used for cities or provinces/states as well? –  sr_magento Jun 9 at 14:00
    
shouldn't disable WYSIWYG? can i use this block in an static block? –  Sepano Jun 9 at 14:34
    
@sr_magento not yet. –  Tim Bezhashvyly Jun 9 at 15:19
    
@Sepano no. it has not connection to WYSIWYG at all. –  Tim Bezhashvyly Jun 9 at 15:20

First of all, disable WYSIWYG editor. Better yet, make it so that WYSIWYG editor is disabled by default: System > Configuration > General > Content Management > WyYWIWYG Options > Enable WYSIWYG Editor and set it to Disabled by Default

Now that we can enter stuff directly:

<script type="text/javascript">
if (geoip_country_code() == 'GB') 
{
    alert("Hello, you are in Great Britain");
}
</script>

Save, reload page and (hopefully) enjoy results ...

share|improve this answer

what you need to do is change the logic where you are displaying the block

1.Wrap this call inside the condition,

<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('geo')->toHtml() ?>

2.By your layout handler if you are calling i.e,

<block type="cms/block" name="geo">
    <action method="setBlockId"><block_id>geo</block_id></action>
</block> 

and call as

$this->getChildHtml('geo') in your phtml file,

wrap this around your condition.

Hope this helps!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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