giorgiopogliani / twig-components Goto Github PK
View Code? Open in Web Editor NEWTwig components inspired from blade components
License: MIT License
Twig components inspired from blade components
License: MIT License
Have you considered adding support for namespaces or subfolders?
An example: I'm making a bunch of components called intro
or header
that lives in different contexts and often are very different.
Thus I want to group them in subfolders, say blog/intro.twig
, faq/intro.twig
etc.
Would it make sense to add support for prefixes to ComponentTokenParser
, and then use the folder structure as a prefix?
Say, something like blogIntro
, faqIntro
etc.? If you nest folders, it would just keep adding it.
So if you have blog/view/intro.twig
that would turn into blogViewIntro
.
I am using Symfony 5.3. Installed the extension.
I tried to add the extension in my services.yaml like this
parameters:
app.name: '%env(APP_NAME)%'
app.upload_dir: '%kernel.project_dir%/%env(APP_UPLOAD_DIR)%'
app.upload_uri: '%env(APP_UPLOAD_DIR)%'
app.upload_max_filesize: '%env(APP_UPLOAD_MAX_FILESIZE)%'
services:
_defaults:
autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
App\:
resource: '../src/'
exclude:
- '../src/DependencyInjection/'
- '../src/Entity/'
- '../src/Kernel.php'
- '../src/Tests/'
componentextension:
lazy: false
class: Performing\TwigComponents\ComponentExtension
tags:
- {name: twig.extension}
arguments:
$relativePath: '%kernel.project_dir%/templates/components/'
when i try to use it in my template it shows like
code for my button.twig component
<button {{ attributes.merge({ class:'text-white rounded-md px-4 py-2' }) }}>
{{ slot }}
</button>
I'd really like to place a controller between the component and the template, for example:
{# /components/templates/table.twig #}
{% spaceless %}
<table {{ attributes.merge({}) }}>
{% if caption is not empty %}
<caption {{ caption.attributes }}>
{{ caption }}
</caption>
{% endif %}
{% for row in rows %}
<tr {{ row.attributes.merge({}) }}>
{% for cell in column %}
<{{ cell.type }} {{ cell.attributes.merge({}) }}>{{ cell.label ?: ' ' }}</{{ cell.type }}>
{% endfor %}
</tr>
{% endfor %}
</table>
{% endspaceless %}
<?php
/**
* /components/controllers/table.php
*/
class table
{
public function __construct($attributes)
{
if (!isset($attributes['caption']) {
throw new Error("You must define a caption to keep this accessible");
}
}
}
Is there any way to implement something like this with this library?
How would you handle filenames with kebab-case
filenames, eg page-header.twig
?
Is Twig nodes always lowercase?
Hello, thanks for your awesome work !
I'm sorry if this is obvious, but i'm trying to use this with a symfony 6 app and i have no idea how to configure this package...
Since twig is somehow autoloaded by symfony I don't how to use the configuration snippet you provide (where and how ?)
/** @var \Twig\Environment $twig */
use Performing\TwigComponents\Configuration;
Configuration::make($twig)
->setTemplatesPath('/relative/directory/to/components')
->setTemplatesExtension('twig')
->useCustomTags()
->setup();
I actually started a very similar project https://github.com/TwigComponents one day before your first commit ;-)
You are still ahead since your code is open source, mine isn't.
Is there any reason why you stuck with the 0.1.0 release?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.