Topics

Slots

Slots are placeholders in theme's layout file that can be filled in with content by a plugin. Instead of directly adding potentially complex PHP code inside your layout, you can put a slot to your layout and populate it with content from within your plugin.

In contrast to the blocks, slots don't allow widgets to be dropped inside.

How to use slots

ImpressPages has several predefined slots. These predefined slots can be used to display a menu, breadcrumb, logo, etc. See the sample usage of predefined slots in examples below.

Generate site logo

<?php echo ipSlot('logo'); ?>

Generate languages

<?php echo ipSlot('languages'); ?>

Generate a menu. Replace menu1 to actual menu you want to display

<?php echo ipSlot('menu', 'menu1'); ?>

See navigation section for full list of options. 

Generate a breadcrumb

<?php echo ipSlot('breadcrumb'); ?>

Generate inline managed TEXT

<?php echo ipSlot('text', array(
    'id' => 'themeName', 
    'default' => 'The default text'
)); ?> 

Full list of settings

Key Required Comment
id Yes

Unique ID of text slot. If you use the same ID in several places, they all will hold the same value.

If you want your text slot to have different value on each page, add Page ID to the id. E.g.

'id' => 'my_text_slot_' . ipContent()->getCurrentPage()->getId()

default Yes

Default content of text slot. Used while there is no value set in the database  yet.

tag

HTML tag to be used to surround the edited content.

P tag can't be used because it conflicts with TinyMCE added P tag. Default value div.

class Class attribute of surrounding HTML tag
attributes Associative array of HTML attributes to be added to surrounding HTML tag. (since 4.2.8)

Since 4.2.2 version you can change TinyMCE configuration of text slot by adding the ipInlineManagementTinyMceConfig function anywhere in your appplication:

var ipInlineManagementTinyMceConfig = function (options) {
    var newConfig = ipTinyMceConfig();

    //any other modifications to original config
    //eg. remove forced_root_block configuration
    newConfig.forced_root_block = false;

    return newConfig;
}

Generate inline managed image

<?php
$options = array(
    'id' => 'testImage',
    'width' => '940',
    'height'=>'200',
    'class' => 'cssclass(optional)',
    'default' => ipThemeUrl('assets/defaultImage.png')
);
echo ipSlot('image', $options);
?>

Create a custom slot

Each widget can introduce any number of slots available to the theme. Simply create Slot class in your plugin. Each method of this class represents a slot. Example bellow creates myFunction slot.

<?php
namespace Plugin\MyPlugin;

class Slot {
    public static function myFunction($params)
    {
        return 'Hello slot!';
    }
}

Use a slot in your theme's layout file

<?php echo ipSlot('myFunction'); ?>

Setting the priority

If there are two plugins implementing the same slot, the one with the higher priority will be used. You can set a priority of slot by specifying underscore character following a numeric value in method's name. Lower number means higher priority. The default priority is 50.

Good practices

If none of the plugins binds to the slot nothing will be printed out. So it is very useful to bind this way when creating themes and plugins that you want to share on ImpressPages Marketplace. Then your themes will not break if some of used plugins are missing.

comments powered by Disqus