agelxnash/mod-laravel

Launch snippets from content (by CMS MODX Evolution)

Maintainers

👁 Agel Nash

Package info

github.com/AgelxNash/modLaravel

pkg:composer/agelxnash/mod-laravel

Statistics

Installs: 836

Dependents: 0

Suggesters: 0

Stars: 4

Open Issues: 0

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

Requires

  • php: >=5.4.0

Requires (Dev)

None

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT 33d177e3707225bb58e1169aeee3eaa1ca4a3474

  • Agel_Nash <agel_nash.woop@xaker.ru>

laravelsnippetsmodxmodx evolution

This package is auto-updated.

Last update: 2026-06-25 11:13:03 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