In the hangout from yesterday there was a discussion point around how best to convert the existing template file documentation to a format that would work for Twig. There was talk of using simply "content" for the variable name instead of "{{ content }}".

I think we should use the full "{{ variable }}" syntax any time we refer to it. It would make it easier to understand exactly what we're talking about and easier to copy and paste.

Comments

soulston’s picture

I'm +1 for this too. I think that it could be confusing if you are referring to a variable if it's not in this format.

steveoliver’s picture

for sure ... I missed the hangout yesterday but actually this morning updated the template conversions instructions docs toward the bottom with this {{ item }} full syntax

fabianx’s picture

Assigned: Unassigned » jenlampton

Please confirm we want to do that from themers perspective.

psynaptic’s picture

I am a themer/frontend guy. It's going to be easier to cut and paste, which is an important feature for a frontend person ;)

Also, it's important that we're consistent in the way we refer to things and will help newcomers to pick up the syntax quicker.

fabianx’s picture

Title: Decide how to document Twig template files » [policy, no patch] Decide how to document Twig template files
Assigned: jenlampton » chx
Category: task » bug
Priority: Normal » Critical
Status: Active » Needs review

Bumping up to critical as we need to solve this.

Assigning to @chx for another round of twitter poll review.

The question is:

- variable - description

in docs

OR:

- {{ variable }} - description

in docs.

fabianx’s picture

Assigned: chx » Unassigned
Status: Needs review » Closed (duplicate)

Discussed with chx.

We have a docs core policy for twig files in #1759168: Comments in twig files [policy, no patch].

The problem is:

{{ var }}  == echo $var

Using {{ var }} in docs would imply {% if {{ var }} %}, which is wrong ...

=> We need to use the simplified version, lets continue discussions in #1759168: Comments in twig files [policy, no patch] - if there is more need.

jenlampton’s picture

We talked about this in the weekly twig meeting today, and we decided that the existing syntax should be sufficient.

In PHPTemplate, we did NOT write this in the docs:

/**
 * @file
 * Default theme implementation to display a node.
 *
 * Available variables:
 * - <?php print $title ?>: the (sanitized) title of the node.
 ...

so there is no reason to include the print statements for Twig, either.

There will be plenty of examples how the variable is being printed, and evaluated, in the Twig code below, and we expect most front-end devs to copy and paste from there as well.

psynaptic’s picture

Aesthetically I think the simpler syntax is better (without the print brackets). The only place I see this breaking down if when we refer to variables within sentences but I guess we can just use the bracket syntax for those cases instead of just the word itself.

jenlampton’s picture

Or we could surround the variable in single quotes or something. I dislike the idea of using the print syntax in sentences since I think it might confuse people, especially when the sentences are talking about testing the values of variables - in those cases using the print syntax would be wrong.

steveoliver’s picture

"So this is how you use the 'element' variable. You can test it in a conditional statement: {% if element == 'h3' %}. You can print output its value like this: {{ element }} ."

compared to

"So this is how you use the element variable. You can test it in a conditional statement: {% if element == 'h3' %}. You can print output its value like this: {{ element }} ."

While my first thought is that single quotes looks nicer (first example), maybe no wrapper (as in the second example) might help us avoid people trying to use the variable WITH the surrounding single quotes. Most people probably will figure it out, but isn't it feasible that people may copy the 'element' variable with the quotes and try to use that when instead they should be using element without quotes?

It may be a little less clear to read? without any quotes, but for the case of people wanting to copy and paste, etc... maybe no wrapper could be a safe option?

Project: » Lost & found issues

This issue’s project has disappeared. Most likely, it was a sandbox project, which can be deleted by its maintainer. See the Lost & found issues project page for more details. (The missing project ID was 1750250)