Extending block and access to the context

153 views
Skip to first unread message

Watchwolf

unread,
Mar 12, 2012, 6:28:34 AM3/12/12
to dotliquid
Hello,

I need a template langage compiler/render for my project. My first
intention was to write my own but this is a bad idea.
Now I am planning to use DotLiquid for my project but I have one
little problem and I whish to know what the best solution is.

Template example:
hi {{name}} \n\n {% block Person %} hello {{name}} {% endblock %}
I have implemented the block "block". Currently it does nothing.

My data:
{ name = "tobi", Person = new {name="watchwolf"} })

The result I need:
hi tobi \n\n hello watchwolf

As you can see:
- the first name is the value of "name". "KEY"
- the second name is the value of "Person.name". "BLOCKNAME.KEY".
Of course I can have a block in a block "BLOCKNAME.BLOCKNAME2.KEY".

Some idea I have:
- update the dictionnay. In the block the dictionnay become the
content of "People". (dictionnay= dictionnay.BLOCKNAME).
- I automatically prefix all Output markup with the blockname.
({{KEY}} = {{BLOCKNAME.KEY}}.

I do not know how dotliquid is written, so I do not know how I can do
this and which solution is the best.

Have you some ideas ?

Alessandro Petrelli

unread,
Mar 12, 2012, 9:21:03 AM3/12/12
to dotl...@googlegroups.com
Hi,
the block tag usage is intended for inheriting/extending a template and doesn't work the way you tried to use it.
Instead, check the example in our website at http://dotliquidmarkup.org/try-online, it should be a good start.
After you have modeled the class according to your needs, your template should look like this: 
hi {{ name }} \n\n hello {{ person.name }}
if you plan to use the ruby naming convention, or 
hi {{ Name }} \n\n hello {{ Person.Name }}
if you plan to use the c# naming convention.

AP

Watchwolf

unread,
Mar 12, 2012, 10:11:50 AM3/12/12
to dotliquid
In fact I have found a way:

http://pastebin.com/7jQDVLBR

The problem is your method is that I need to prefix the name with
"person".

On 12 mar, 14:21, Alessandro Petrelli
<alessan...@alessandropetrelli.com> wrote:
> Hi,
> the block tag usage is intended for inheriting/extending a template and
> doesn't work the way you tried to use it.
> Instead, check the example in our website athttp://dotliquidmarkup.org/try-online, it should be a good start.
> After you have modeled the class according to your needs, your template
> should look like this:
> hi {{ name }} \n\n hello {{ person.name }}
> if you plan to use the ruby naming convention, or
> hi {{ Name }} \n\n hello {{ Person.Name }}
> if you plan to use the c# naming convention.
>
> AP
>
Reply all
Reply to author
Forward
0 new messages