像laravel刀片中的短代码一样创建Wordpress

Rom*_*usa 2 php wordpress shortcode laravel laravel-4

我有一个需要动态的邮件模板(在laravel刀片中)(所以它应该保存在我认为的数据库中).这是registration_complete.blade.php:

      <html>
       <body>
         {{$dynamic_content_from_database}}
        </body>
      </html>
Run Code Online (Sandbox Code Playgroud)

$ dynamic_content_from_database值来自我使用的WYSIWYG.这是我工作的管理: 在此输入图像描述

我需要找到一种方法,管理员用户可以使用变量内部或短代码来管理模板的内容.就像在WordPress中一样,他们使用短代码将动态值放入内容中.我尝试回显$ dynamic_content_from_database.但它只是回应了[username]字符串.我试图搜索网络,但我没有运气.顺便说一句,我使用了laravel 4.2.这个表格是在成功注册后发送的.

fut*_*ien 5

我认为更好的方法是在将dynamic_content_from_database放入控制器的blade-template之前准备它.

在路上

Route::post('register', ['as'=>'register.post', 'uses'=> 'path\to\register\form\namespace@register']
Run Code Online (Sandbox Code Playgroud)

在控制器中(简单,但不是最好的方式):

public function replacement($string, array $placeholders)
{
    $resultString = $string;
    foreach($placeholders as $key => $value) {
        $resultString = str_replace('[' . $key . ']' , trim($value), $resultString, $i);
    }
    return $resultString;
}

public function register() {
    $data = Input::all();
    //... Dont forget about validation
    //loading template from database example
    $template = Template::where('name', 'register.success')->firstOrFail();
    $content = $this->replacement($template['text'], $data);
    View::make('register.success', ['content' => $content]); //or send mail with $content as you want
}
Run Code Online (Sandbox Code Playgroud)

为了获得更好的解决方案,您可能需要创建TemplateService,在配置中启用它并通过App加载.