Installation:
composer require auvernhatinternet/markflat-editor
Add to config/bundles.php:
MarkFlatEditor\MarkFlatEditorBundle::class => ['all' => true],
Configure .env:
ADMIN_PASSWORD=your_secure_password_here
First Use Case:
Access the editor at /admin?password=your_secure_password_here. The interface will allow you to edit Markdown files stored in a predefined directory (default: var/markflat/).
config/packages/markflat_editor.yaml (if it exists) or inspect the bundle’s default configuration for the storage_path setting.var/markflat/test.md) and verify it appears in the admin panel.{{ render_markdown('var/markflat/test.md') }}
File Management:
var/markflat/docs/guides/). The admin panel will reflect this structure.Dynamic Content Rendering:
{% for file in get_markflat_files('var/markflat/docs') %}
<h2>{{ file.name }}</h2>
{{ render_markdown(file.path) }}
{% endfor %}
Authentication & Security:
ADMIN_PASSWORD in .env secures the admin panel. For production, consider:
var/markflat/) has restrictive permissions (e.g., chmod 750).Customization:
vendor/markflat-editor/templates/ to your project’s templates/bundles/markflat_editor/.Documentation Site:
var/markflat/docs/.Blog System:
title, date) via frontmatter and parse it in Twig:
{% set post = parse_markflat_metadata('var/markflat/posts/2023-intro.md') %}
<h1>{{ post.title }}</h1>
<p>{{ post.date }}</p>
{{ render_markdown('var/markflat/posts/2023-intro.md') }}
Multi-Language Support:
var/markflat/en/, var/markflat/fr/).Storage Path Configuration:
var/markflat/, but this can be overridden in config/packages/markflat_editor.yaml:
markflat_editor:
storage_path: '%kernel.project_dir%/custom/markflat'
Password Security:
ADMIN_PASSWORD is stored in plaintext in .env. For production:
ParameterBag or env() function to encrypt the password.Markdown Parsing Quirks:
Caching Issues:
php bin/console cache:clear
Check Logs:
APP_DEBUG=1 in .env) to log errors related to file access or rendering.Verify File Paths:
dump() to debug file paths:
{{ dump(get_markflat_files('var/markflat')) }}
Test with Minimal Files:
Custom Twig Functions:
// src/Twig/AppExtension.php
namespace App\Twig;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
class AppExtension extends AbstractExtension
{
public function getFunctions()
{
return [
new TwigFunction('custom_markdown_render', [$this, 'renderWithCustomLogic']),
];
}
public function renderWithCustomLogic(string $path): string
{
// Custom logic here
return file_get_contents($path);
}
}
Event Listeners:
// config/services.yaml
App\EventListener\MarkFlatListener:
tags:
- { name: kernel.event_listener, event: markflat.editor.render, method: onRender }
Override Admin Panel:
FileSystem component).Environment-Specific Settings:
%kernel.environment% to set different storage paths per environment:
markflat_editor:
storage_path: '%kernel.project_dir%/var/markflat_%kernel.environment%'
Disable Admin Panel:
admin_enabled: false in the config to hide the /admin route entirely:
markflat_editor:
admin_enabled: false
File Filtering:
.gitignore). Add a custom Twig filter to exclude them:
{% set visible_files = get_markflat_files('var/markflat')|reject('isHiddenFile') %}
How can I help you explore Laravel packages today?