Skip to content

Launch snippets from content (by CMS MODX Evolution)

License

Notifications You must be signed in to change notification settings

AgelxNash/modLaravel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Launch snippets from content (by CMS MODX Evolution)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages