Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

159
Visualizações
Angular 2 and Twig site builder

I am trying to build a project combining Angular 2 and Twig. At a high level the angular app would basically be a site generator. In the project there is a views folder that would contain a number of different site templates, which are Twig files. One of the components makes a request for a JSON file, which provides specific site information like the title, header, content, etc. It also specifies some sort of config variable that tells Angular which template to pull. That template is combined with data in the JSON and the site is compiled. Does something like this sound possible?

I found this project and the developer kindly updated it to support the latest version of Angular. I put together a basic project with the angular cli and am trying to get it to render a Twig file as a template. If I include the Twig file as a template string it renders fine. If I include it as a templateUrl like this:

Component

import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { Twig } from '@manekinekko/angular-twig';

@Twig({
  selector: 'app-test',
  templateUrl: '../views/test.html.twig',

   context: {
       title: 'Angular2 ❤ Twig',
       content_1: 'blah',
       content_2: 'content 2'
   },
})

export class TestComponent implements OnInit {

 content_1 ='content 1';
 constructor() { }

    ngOnInit() {
    }

}

Template

{{ content_1 }}

I am getting the error that content_1 is not defined, though it works fine as a template string. I am not quite sure what is going on. I know I have the template in a separate director than the component. Could that be the problem? Ideally I would want the app to work that way so I can have all the separate site template files in a separate folder.

I welcome any thoughts to a totally alternative approach as well. Thanks!

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Not sure if you still search for a solution, but I found this to your problem:

{{'{{' ~ aTwigVariable ~ '}}'}}

So your template part would be

{{'{{' ~ content_1 ~ '}}'}}

Hope this helps :)

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda