Comments (13)
Sorry if I am being verbose on this thread, but it's important that we all understand the pros and cons of each solution.
Right now Fluid will strip the whitespace before a block tag content, which happens in this case. The idea is that in most cases we don't want to render indentations before code flow tags, like assign
, if
, for
, ...
Take this example:
{% for i in (1..10) %}
{% assign foo = i %}
{% endfor %}
Without this default behavior, we would get an output containing 10 empty lines, though nothing should be rendered.
You can take a look a this file for tests that show how it handles whitespace: https://github.com/sebastienros/fluid/blob/dev/Fluid.Tests/WhiteSpaceTests.cs
What I would suggest right now to solve your problem, is that we create a custom tag that would indent a section, like this:
{% indent: 4 %}
{% include 'foo' %}
{% endindent %}
The result would be that every line in the block would be indented by 4 spaces. We would add an optional parameter with the string to repeat, like tabs.
from fluid.
As I can see from your code snippet before, seems the for
statement can't preserve the spaces.
@sebastienros is this how it works?, or is it a bug? Coz I see DotLiquid preserve the spaces
from fluid.
from fluid.
For simplification we should preserve the whitespace, or add an option as you suggest before, but I don't think specifying the behavior per tag is a good option
from fluid.
from fluid.
Sounds good, let me check ..
from fluid.
just fyi, dotLiquid supports this scenario only if the contents of my AutoProperty.liquid example are only one line.
If my AutoProperty.liquid would be this:
[Column]
public {{ col.PropertyType }} {{ col.PropertyName }} { get; set; }
The results in dotLiquid would be
[Column]
public string Name { get; set; }
[Column]
public int PrincipalId { get; set; }
I would expect multiline included files to be evenly whitespaced
from fluid.
if the contents of my templates are only one line
That's not what it does, it's just rendering the whitespace, for each time the block is rendered. Nothing to do with {% include %}
or the fact that it's only one line. It happens to look how you would like because it does it.
What could be done though is to add a property to the include tag such that new lines are also padded. And the padded value could be global variable in your main template such that you can call it recursively.
We should still handle the whitespace issue that you have found. And look at liquid if it supports what I just described.
from fluid.
/cc @RSuter I assume you would love that
from fluid.
relevant liquid issue: Shopify/liquid#925
It seems liquid and dotLiquid behave exactly the same in this scenario.
Just a question, but why does liquid strip whitespaces by default? Is'nt that what {% -%}
is for?
EDIT, I read your docs ;) and it indeed seems like a nice improvement over liquid, but I think the Include tag is the exception to this rule
I think your indent solution is a good idea, as it would keep the compatibility with liquid templates. Depending on how Shopify/liquid#925 turns out, you could add the new tag syntax discussed there and deprecate the indent tag, or keep both.
For me this isn't that big (urgent) of an issue, I'm currently using Roslyn at the end of my code generation to format everything nicely, but it would be nice to ditch that dependency
from fluid.
You are right, we still need to fix the fact that the whitespace is ignored in this case.
To behave exactly the same as the reference implementation we could have a flag. Let me check.
from fluid.
Make an option such as EnableWhitespace
will be handy
from fluid.
The 2.x version doesn't strip whitespaces by default anymore, and there are options to change the behavior for each type of tags.
from fluid.
Related Issues (20)
- Question: Is it possible to use Layout and Sections tags with streams rather than paths HOT 2
- Question: Multiple arguments/parameters for tag HOT 3
- Access root object from template HOT 3
- Include statement circular dependency HOT 8
- Current local date and time not converting to specified timezone HOT 2
- Question: Introspection of parsed template HOT 6
- Question: is this library suited for implement something like Microsoft Guidance?
- {% render "filename" %} with custom extensions HOT 2
- Access properties of dictionary value HOT 1
- Fluid.Tags compatibility method after upgrading to a new version HOT 1
- Question: Update underlying Liquid version HOT 2
- Layout support doesn't seem to work in 2.4.0 HOT 10
- Hope size supports null HOT 1
- Missing fluid compatibilty table and roadmap HOT 1
- Synchronous operations are disallowed
- Fluid prints nothing inside for ..in loop HOT 2
- Make TemplateContext.LocalScope public
- Template not rendering
- Recusive variable resolving
- Include/Render Statement Cache Not Refreshed When File Content Changed HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fluid.