The options parameter

There are two different functions to quickly render an Ad:

Both of these methods accept an "options" parameter. The options parameter is a configuration object, containing one or more of the following groups:

{
    'image': {},
    'attr': {},
    'js': {}
}

# Default Options

Unless you manually override them, these are the default options for every Ad that gets rendered.

{
    'image': {
        'transform': null,
        'retina': false
    },
    'attr': {
        'class': 'adWizard',
        'style': 'cursor:pointer'
    },
    'js': {
        'click': 'adWizard.click({id}, \'{url}\')'
    }
}

All of these options can be overridden in Twig.


# image

You can overwrite these defaults by following the instructions for image transforms...


# attr

Any attributes that you want to apply to the <img> tag being generated.

{
    'attr': {
        'alt': '{myAltField}',
        'title': '{myAltTitle}'
    }
}

By default, these reference the attributes of your Ad element. You can use a dot-notation to drill deeper into related elements.

{
    'attr': {
        'alt': '{image.imageAltField}',
    }
}

# js

Any JavaScript events that could be prefixed with on are welcome here...

{
    'js': {
        'click': "alert('Ad clicked')",
        'mouseenter': "alert('Ad hovered')"
    }
}

These commands will be automatically prefixed with on and added to the attr options.

It's effectively a shortcut for this:

{
    'attr': {
        'onclick': "alert('Ad clicked')",
        'onmouseenter': "alert('Ad hovered')"
    }
}