On 8/9/17 5:30 AM, Suliman wrote:
Big thanks! Now I understand. Now i redone dlang.ru in diet templates.
Am I right understand that include is needed only for small includes
without any nesting levels?
No, includes can be as big as you want, with as many nested levels as
you want. You just can't alter the structure of the including template.
I think what you are getting hung up on is that the indentation of the
include has nothing to do with the indentation of the template that's
including it. It's not like the text is copy-pasted and then evaluated
in that context.
So if you have:
the resulting html file is going to be:
<!-- all the contents of x>
x cannot insert data *outside* that element, no matter how you indent it.
You would use includes when you have repeated html that you need in many
places. For instance, if you have many places that you display the
contents of a database row somehow, you can save that snippet in a
template, and then just include it whenever you need the same thing.
You would use blocks when you have a framework that you want to be the
same, but need to vary the inner html. So essentially the boilerplate
etc.). It's so you don't have to repeat the structure in every file.
I will say, there are some annoying limitations to the diet format.
Sometimes you *want* to vary the structure based on variables, and it's
hard to do. For example, I have a place where I output essentially a
calendar as a table. Each row is a different day, each column is an item
on that day. The input is a single sorted (by date) array of items. But
there's no "good" way to say "ooh, this is a new day, close this table
row and open a new one" and still keep the nice structure of the diet
templates. Yes, I can output the html manually, but it's ugly. What I
ended up doing is just splitting the array into another array of days,
each element an array of items for that day.