Skip to content
Sunel edited this page Sep 14, 2015 · 3 revisions

Caching

This package supports caching out of the box.

Add cache lifetime to the block class and provide the cache id. You also set the cache group and tag through CONSTANTS so that they can be cleared using it.

    /**
     * Cache group Tag.
     */
    const CACHE_GROUP = 'block_html';

    /**
     * Cache tags data key.
     */
    const CACHE_TAGS_DATA_KEY = 'cache_tags';

    public function boot()
    {
        $this->addData([
            'cache_lifetime' => Carbon::now()->addMinutes(10),
        ]);
    }

    /**
     * Retrieve cache key data.
     *
     * @return array
     */
    public function getCacheKeyInfo()
    {
        $cacheId = [
            'SOMEUNIQUEID',
            $this->getNameInLayout(),
        ];

        return $cacheId;
    }

Adding Top Menus

You can added Top menus dynamicaly by listening to event page.block.html.topmenu.getMenus.before.

    Event::listen('page.block.html.topmenu.getMenus.before', function ($menu, $block) {
        $menu->add('Men', 'menu');
        $menu->add('Women', 'women');
    });

It uses the popular package lavary/laravel-menu for menus.

Adding Top Links

You can add links by referencing the block top.links

<home>
    <reference name="top.links">
        <action method="addLink" translate="label title">
            <label>My Account</label>
            <url helper="\Layout\Page\Html@getAccountUrl"/>
            <title>My Account</title>
            <prepare/>
            <urlParams/>
            <position>1</position>
        </action>
        <action method="addLink" translate="label title">
            <label>Register</label>
            <url>/auth/register</url>
            <title>Register</title>
            <prepare/>
            <urlParams/>
            <position>2</position>
         </action>
         <action method="addLink" translate="label title">
            <label>About</label>
            <url>about</url>
            <title>About</title>
            <prepare>true</prepare>
            <urlParams>
                <id>bar</id>
                <foo>bar</foo>
            </urlParams>
            <position>3</position>
            <liParams>
                <id>bar</id>
                <foo>bar</foo>
            </liParams>
            <aParams>
                <id>bar</id>
                <foo>bar</foo>
            </aParams>
         </action>
    </reference>
</home>

MultipleHandles

This allows developers to target their layout updates to multiple layout handles at once.

    <home ifhandle="customer_logged_in">
        <reference name="content">
            ...
        </reference>
    </home>