question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Twig component renders incorrectly from the docs

See original GitHub issue

Steps to reproduce the issue

  1. clone https://github.com/uandco/fractal-twig-issue
  2. run npm install
  3. run fractal start --sync

The navigation component shows up OK when viewed as a component or rendered via another component (I rendered it in the example component)

The rendering fails when rendered from the docs (HTML code is displayed). I tried to use the twig engine for docs too but get the same result.

Reproduces how often:

100%

Reduced test case

https://github.com/uandco/fractal-twig-issue

Context

  • Fractal version: 1.3.0
  • Node version: 10.15.1
  • OS: MacOS 10.14.6

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mihkeleidastcommented, Dec 24, 2020

If some HTML is indented and has an empty line before it, our markdown parser will convert that to a code block, for example:

some text

    <div>this is now a code block</div>

In your component, your macro ends with a newline:

...
</ul>
{% endmacro %}

These newlines are also visible when viewing the component source in the browser.

To remove the newlines and fix the issue, an inline spaceless helper can be added to the endmacro tag:

...
</ul>
{%- endmacro %}

This will trim the ending newline from the macro output & fix the issue.

0reactions
mel-millercommented, Oct 28, 2020

I’m trying to figure out why this is happening to some blocks of code and not others. I don’t have a huge sample size yet, but this only seems to be happening when the base templates (in my case Twig) are multi-line and have a for loop in them.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is this not rendered by the twig template? - Stack Overflow
Try in your config.yml. twig: paths: '%kernel.root_dir%/../src/Something/Bundle/SomethingBundle/Resources/public/templates': my_templates.
Read more >
The flexible, fast, and secure template engine for PHP - Twig
Rendering Templates. To load a template from a Twig environment, call the load() method which returns a \Twig\TemplateWrapper instance:.
Read more >
Emulating Components in Twig - DEV Community ‍ ‍
When I work in Twig templates, not having access to bona fide components is definitely one of the things I miss most.
Read more >
3 Ways to Reuse Twig Templates in Symfony | Scout APM Blog
Code for caching the templates is: $twig = new Twig_Environment($loader, ['cache' => '/templates/cache']); Filter, classifiers, and other ...
Read more >
Working With Twig Templates - Drupal
When rendering an article node Drupal will first look for the node--article.html.twig template file and use it if it exists. If it doesn't, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found