{"id":20601202,"url":"https://github.com/cleverage/twigjs-drupal-render-array","last_synced_at":"2025-07-29T12:13:03.210Z","repository":{"id":66761325,"uuid":"116797317","full_name":"cleverage/twigjs-drupal-render-array","owner":"cleverage","description":null,"archived":false,"fork":false,"pushed_at":"2018-01-09T10:02:44.000Z","size":23,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-09T16:53:15.132Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cleverage.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-01-09T09:48:55.000Z","updated_at":"2018-04-26T13:28:10.000Z","dependencies_parsed_at":"2023-02-24T22:00:41.175Z","dependency_job_id":null,"html_url":"https://github.com/cleverage/twigjs-drupal-render-array","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/cleverage/twigjs-drupal-render-array","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cleverage%2Ftwigjs-drupal-render-array","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cleverage%2Ftwigjs-drupal-render-array/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cleverage%2Ftwigjs-drupal-render-array/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cleverage%2Ftwigjs-drupal-render-array/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cleverage","download_url":"https://codeload.github.com/cleverage/twigjs-drupal-render-array/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cleverage%2Ftwigjs-drupal-render-array/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267685100,"owners_count":24127706,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-29T02:00:12.549Z","response_time":2574,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-16T09:09:00.836Z","updated_at":"2025-07-29T12:13:03.202Z","avatar_url":"https://github.com/cleverage.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Twig drupal render array\n\nThis project provide a function to transform regular js object to equivalent to Drupal 8 `RenderArray`.\n\n\n## Why?\n\nWe need to build static view from twig Drupal 8 template and fake data with node and twig.js.\n\nBut twig.js do not support some Drupal 8 behavior\n\n\n## Install\n\n```bash\nnpm install cleverage/twigjs-drupal-render-array#master\n```\n\n\u003e NB: this module will be published on NPM soon\n\n```javascript\nconst Twig = require('twig');\nconst dataTransformer = require('twigjs-drupal-render-array')(Twig);\n```\n\n## Use\n\n```javascript\nconst data = {\n  \"#theme\": \"index\",\n  \"#property\": \"Condimentum Pharetra\",\n  \"#another_property\": 666,\n  \"children\": {\n    \"#theme\": \"partial\",\n    \"#yolo\": \"Bibendum Ullamcorper Dolor\",\n    \"otherChild\": {\n      \"#theme\": \"partial\",\n      \"#yolo\": \"second depht\"\n    }\n  }\n};\n\nTwig.renderFile('myTemplate.html.twig', dataTransformer(data), (err, result) =\u003e {\n  console.log(result);\n});\n```\n\n## How it work\n\nTwig.js use `.toString()` method to render an Object, so we create two new type of Object:\n\n * `RenderVar`: `.toString()` return render of twig file matching `#theme` entry with every var without `#`\n * `RenderElement`: `.toString()` return render of twig file matching `#theme` entry with data in a variable named by `render element` key from data\n * `RenderCollection`: `.toString()` return joined string of each children\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcleverage%2Ftwigjs-drupal-render-array","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcleverage%2Ftwigjs-drupal-render-array","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcleverage%2Ftwigjs-drupal-render-array/lists"}