Scripter allows you to load CSS and JavaScript files for Nette Framework.
The best way to install DIPcms/Scripter is using Composer:
$ composer require dipcms/scripter
extensions:
scripter: DIPcms\Scripter\DI\ScripterExtension
#Default settings
scripter:
temp_dir: %tempDir%
url_path_name: 'getsource'
default_syntax: 'asp' #synatxe: latte, double, asp, python, off
Rendering is performed by Nette Latte (template engine) Macros are written with the help of ASP tags. It depends on the settings. You can also use:
- latte:
{ ... }
- double:
{{ ... }}
- asp:
<% ... %>
- python:
{% ... %}
and{{ ... }}
Details on how you can find syntax
<%file "font.ttf"%>
Save the file to cahce and creates a link to the file.<%img "images.jpg"%>
Save the image to cahce and creates a link to the image.
Default macro can be found Latte
Adding Parameters to file
# use DIPcms\Scripter\Scripter;
$scripter->parameter_name = "value";
Add file
# use DIPcms\Scripter\Scripter;
$scripter->addFile(__DIR__ . "/style.css");
Create css file style.css
body{
background: <%img "bg.jpg"%>;
width: <%$width%>px;
}
Your application
namespace App\Presenters;
use Nette;
use DIPcms\Scripter\Scripter;
class HomepagePresenter extends Nette\Application\UI\Presenter{
/**
* @var Scripter @inject
*/
public $scripter;
public function renderDefault(){
$this->scripter->width = 50;
$this->scripter->addFile(__DIR__.'/style.css');
}
}
Scripter automatically add a link in the header to the CSS and JS file.
<head>
<meta charset="utf-8">
#............
<script type="text/javascript" src="/getsource/6666cd76f96956469e7be39d750cc7d9/js"></script>
<link rel="stylesheet" href="/getsource/6666cd76f96956469e7be39d750cc7d9/css">
</head>