Save blade templates to database rather than file

后端 未结 3 641
说谎
说谎 2020-12-20 01:44

I want to save my blade templates to database, because the header and footer of each page is customizable for the user. I want to let

3条回答
  •  一整个雨季
    2020-12-20 02:43

    I realised that I can improve security and caching if I just let them insert the static content only. The only thing I need to change is the main content, so I can just let them set a token where the content is to be placed. As is in the above answer by @huzaib-shafi , I did the following...

    //In controller
    $content = View::make('final',compact('data'));
    $token = "", $content, $templateInDatabase);
    $view = str_replace_first("<%token%>", $token, $view);
    $view = str_replace_first("<%scripts%>", $scripts, $view);
    
    return $view;
    

    This enforces them to use bootstrap in their template, because I use bootstrap styles in my blade templates, but it is acceptable in my case.

提交回复
热议问题