Open gentisaliu opened 10 years ago
I agree MtHaml needs some examples.
Basically, the rules are as follows:
-
, after =
, in html attribute values, in #{...}
{% twig code %}
becomes - twig code
- ...
tags followed by indentation are closed automatically (- if foo
is rendered as {% if foo %} ... {% endif %}
){{ twig code }}
becomes either = twig code
or #{twig code}
{{ .. }}
or in {% .. %}
: variables, expressions, tags, filters, macro calls, macro declarations, ...We could write some examples in the wiki: https://github.com/arnaud-lb/MtHaml/wiki
Thanks for getting back to me... I was wondering whether it is possible to define attribute methods, as per the HAML reference: http://haml.info/docs/yardoc/file.REFERENCE.html#attribute_methods
Yes, this syntax is supported. The function has to return an array of name=>value.
Also works with interpolations:
%p(attrs()) // attrs() should return an array
%p(#{attrs}) // attrs() should return a string (e.g. symfony's form_enctype() heper)
Great, though the part I am having difficulties with is in defining the attribute method.
I tried both
def attrs()
...
end
- def attrs()
...
An illegal nesting exception is thrown in the first case, whereas in the second I get an "Unknown tag name "def"" error.
def attrs()
is how you define a method in ruby. You should use twig syntax ;)
- macro attrs()
foo="bar" bar="baz"
Since macros in Twig return strings, you should use the #{...} syntax, too:
%p(#{attrs()})
Wonderful, thank you for your timely responses! I'll try and add something to the wiki later.
Some example HAML templates would be in order for devs who are interested in using this bundle in their Symfony projects, focusing on Twig <-> Haml interoperation, e.g.
... and the list goes on. The current documentation/examples are very scarce.
I could help with some use cases with which I had difficulties or I am stuck at, if you like.