Skip to content

Latest commit

 

History

History
48 lines (40 loc) · 1.31 KB

README.md

File metadata and controls

48 lines (40 loc) · 1.31 KB

Configuration

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