PHP code example of besnovatyj / yii2-cms-shortcode

1. Go to this page and download the library: Download besnovatyj/yii2-cms-shortcode library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

besnovatyj / yii2-cms-shortcode example snippets


   'components' => [
       'shortcode' => [
           'class' => 'modules\shortcode\components\ShortcodeManager',
       ],
   ],
   

   // Регистрация виджетного шорткода
   \Yii::$app->shortcode->registerWidget('gallery', 'common\widgets\GalleryWidget');

   // Регистрация текстовых шорткодов
   \Yii::$app->shortcode->registerText('homeUrl', 'https://example.com');
   \Yii::$app->shortcode->registerText('siteName', 'My Site');
   

   echo \modules\shortcode\widgets\ShortcodeContent::widget([
       'content' => 'Visit %siteName% at %homeUrl% or %unknown%. See our [gallery, id=123, title="Photos", count=5]Photos[/gallery] or [unknown, id="1"].',
   ]);
   

      if (is_numeric($value)) {
          $value = strpos($value, '.') !== false ? (float)$value : (int)$value;
      }
      

      if ($replacement === null) {
          \Yii::warning("Unknown text shortcode: $shortcode");
          return $matches[0];
      }
      

echo \Besnovatyj\Shortcode\widgets\shortcodesList\ShortcodesList::widget();

// Настройки под конкретную страницу
echo \Besnovatyj\Shortcode\widgets\shortcodesList\ShortcodesList::widget([
    'buttonLabel'    => 'Справка по шорткодам',
    'buttonClass'    => 'btn btn-outline-secondary btn-sm',
    'buttonIcon'     => 'bi bi-braces',
    'showCounter'    => true,   // счётчик шорткодов в кнопке
    'modalTitle'     => 'Доступные шорткоды',
    'showModuleLink' => true,   // кнопка перехода на главную модуля
]);