1. Go to this page and download the library: Download geniv/nette-front-editor 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/ */
geniv / nette-front-editor example snippets
use FrontEditorControl;
//$this->template->frontEditorEnable = $this->isFrontEditorEnable();
//$frontEditor->setAcl($this->isFrontEditorEnable());
//$frontEditor->getFrontEditorEnableHash();
//<a n:href="FrontEditorDisable!" n:if="$frontEditorEnable" class="ajax">odhlasi se z edit modu</a>
//{control frontEditor.'-identText1'}
protected function createComponentFrontEditor(FrontEditor $frontEditor): FrontEditor
{
$frontEditor->setTemplatePath(__DIR__ . '/templates/frontEditor.latte');
$frontEditor->setAcl($this->user->isAllowed($this->getName(), 'edit'));
$frontEditor->setData($this['config']->getEditor(static::IDENTIFIER));
$frontEditor->onSuccess[] = function (Form $form, array $values) {
try {
if ($this['config']->setEditor(static::IDENTIFIER, $values['content'])) {
$this->flashMessage($this->translator->translate('front-editor#onsuccess'), 'success');
}
} catch (\Dibi\Exception $e) {
$this->flashMessage($e->getMessage(), 'danger');
}
$this->redirect('this');
};
return $frontEditor;
}
use FrontEditorControl;
protected function startup()
{
parent::startup();
$this->template->frontEditorEnable = $this->isFrontEditorEnable();
}
protected function createComponentFrontEditor(FrontEditor $frontEditor): Multiplier
{
$frontEditor->setTemplatePath(__DIR__ . '/templates/frontEditor.latte');
$frontEditor->setAcl($this->isFrontEditorEnable());
return new Multiplier(function ($indexName) use ($frontEditor) {
$data = $this['config']->getDataByIdent($indexName);
if (!$data) {
$this['config']->setEditor($indexName, $indexName); // create if not exists
return $frontEditor;
}
// set type and add variable to frontEditor
$frontEditor->getFormContainer()->setType($data['type']);
$frontEditor->addVariableTemplate('type', $data['type']);
$frontEditor->setData($data['content']);
$frontEditor->onSuccess[] = function (Form $form, array $values) use ($data) {
try {
if ($this['config']->editData($data['id'], ['content' => $values['content']])) {
$this->flashMessage('done', 'success');
}
} catch (\Dibi\Exception $e) {
$this->flashMessage($e->getMessage(), 'danger');
}
$this->redirect('this');
};
return clone $frontEditor;
});
}