-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Explore the Twig integration with Angular 2 #1
Comments
1. Twig template to Angular 2 template.Twig template
Angular 2 template
Twig variables |
2. Twig as a template engine in Angular 2A quick and dirty solution would be...
We also include a
with something like: //...
var _isTwig = template.templateUrl.endsWith('.twig');
if(_isTwig) {
templateContent = twig({
data: templateContent
}).render(new directiveType.runtime());
}
//... This code simply checks if the current loaded template is a Twig file (from the extension), and runs the
@Component({
selector: 'angular2-comment-field',
templateUrl: '/core/themes/classy/templates/field/field--comment.html.twig',
// ...
})
class DrupalCommentField {
// Twig template variables
private comments: string = 'comments';
private label_hidden: string = 'label_hidden';
private field_name: string = 'field_name_1';
private field_type: string = 'field_type_1';
private label_display: string = 'label_display_1';
// Drupal Template Function: attributes.addClass()
private attributes = {
addClass: (args) => {
return ` class="${ args.join(' ') }" `;
}
}
// Drupal Template Function: title_attributes.addClass()
private title_attributes = {
addClass: (args) => {
return ` class="${args.join(' ')}" `;
}
}
constructor() {}
} This is the default (unmodified!) Twig template:
DONE! With these 3 steps, we were able to load a .twig template, compile it using the Twig.js library and pass basic variable to the template. See this commit for more code b22aacb Notes:
|
That should not be an issue. What is not clear in my head is if the twig and angular templates could be made to be semantically equivalent.
should be easy.
In angular you can insert dom like this: |
This is the scariest/most complex part. This is where Drupal's "Render API" enters the picture. The Render API allows you to write "render arrays", which are nested associative arrays (PHP lingo for the "map" or "dictionary" data structure in CS) that allow developers to declaratively indicate which HTML should be rendered. Why?
A bit more high-level context about our Render API which I think will help you relate to it more easily:
I'm very curious to see how you're going to tackle this! |
@mhevery aren't we going to loose control over those components if we just insert their DOM?
@wimleers Thanks for all the details. This is gonna be useful when digging inside Drupal world which is going to be my next step. |
@manekinekko Let me know whenever you're stuck on something, whether it's code or understanding Drupal stuff. Happy to jump on a call/hangout too. |
Yes, |
@mhevery In order to use the For instance (see diagram below), I am able to use the |
that is correct. Just make a component on the fly.
NOTE: Selector can not have spaces or |
@mhevery I am using this selector |
@tbosch We should throw an error. I am not sure what exactly happens, perhaps we match on |
I added Tobias to this private repo. |
I have been trying to incorporate Twig into my Angular 2 CLI project, using |
A rendered comment (like all rendered output in Drupal) can be heavily customized by themes. For example, comment.html.twig can be overridden with entirely different markup. In this project, we would like to explore two different architectural approaches:
Dedicated Drupal thread https://github.com/acquia/js-exploration/issues/4
The text was updated successfully, but these errors were encountered: