agelxnash/mod-laravel

Launch snippets from content (by CMS MODX Evolution)

dev-master 2018-04-04 08:50 UTC

This package is auto-updated.

Last update: 2024-04-25 06:50:24 UTC


README

You will want to run the following command to publish the config to your application, otherwise it will be overwritten when the package is updated.

php artisan vendor:publish --provider="AgelxNash\modLaravel\ServiceProvider"

Now you can edit the file config/modx.php

Usage

Create your snippet in the config file config/modx.php

return array(
    'snippets' => array(
        'user' => function($params){
            $id = isset($params['id']) ? (int)$params['id'] : 0;
            $field = (isset($params['field']) && in_array($params['field'], array('name', 'email'))) ? (string)$params['field'] : 'name';
            $userObj = App\Models\User::findOrNew($id);
            return $userObj->{$field};
        }
    )
);

Now you can call a snippet user

$text = 'Some data: [[example? &id=`asd`]]. User: [[user? &id=`2`]]';
return Modx::mergeSnippets($text);

As a result, you get something like this

Some data: Array ( [id] => asd ). User: Admin

Attention

Do not get carried away with this garbage. It is absolutely safe and can lead to cracking of your site.

Why You Need

For example, you have a slider. And you want to insert it in any place

See