Timber/TWIG for Wordpress - Questions about some basics









up vote
0
down vote

favorite












For instance in the Timber Documentation we have lots of examples like the following:



% for item in menu.items %

post.author.name


Now the "item" and the "menu" etc. are all predefined, and nowhere defined by a user in the files (otherwise by my understanding Timber and TWIG would not make much sense).



What I do not understand is where I can find out a list these. In the Docs of Timber, there are a bunch of examples, then when I compare them to the Timber Starter Theme for Wordpress, I see a bunch of them, which aren't even mentioned in the documentations.



  1. Where do I find a list of all available items?

  2. What is the logic behind these items?









share|improve this question





















  • To view all accessible variables u could do something like e.g. keys)
    – DarkBee
    Nov 6 at 7:43











  • @DarkBee So how come there is no list of prebuild items? I don't get how I should learn to use Timber. How do I get a hang of it, do you have a few links? If you tell me, after reading the entire Docs I'd get it, I'm glad to do that. The problem for me is, I don't even know how what I am looking for is called. Nowhere is mentioned, if I have to make all of these "items" myself, or if they are all prebuilt or whatever. I actually have no idea what is going on, and what I have to study.
    – frizzant
    Nov 6 at 7:50










  • I'm not actually using timber myself, i'm just using twig actually but it seems the new documentation can be found over here
    – DarkBee
    Nov 6 at 8:02











  • @DarkBee Those are the ones I was working with. My issue is that I can't just go and guess variables to output and hope for the best. Is there any chance you could help me with some questions a bit more in detail? I know this is dumb to ask for, however there isn't enough material on the web to help me - it's mainly this basic questions about the Variables etc. I'm trying to get them answered for more than a week now :(
    – frizzant
    Nov 6 at 8:21














up vote
0
down vote

favorite












For instance in the Timber Documentation we have lots of examples like the following:



% for item in menu.items %

post.author.name


Now the "item" and the "menu" etc. are all predefined, and nowhere defined by a user in the files (otherwise by my understanding Timber and TWIG would not make much sense).



What I do not understand is where I can find out a list these. In the Docs of Timber, there are a bunch of examples, then when I compare them to the Timber Starter Theme for Wordpress, I see a bunch of them, which aren't even mentioned in the documentations.



  1. Where do I find a list of all available items?

  2. What is the logic behind these items?









share|improve this question





















  • To view all accessible variables u could do something like e.g. keys)
    – DarkBee
    Nov 6 at 7:43











  • @DarkBee So how come there is no list of prebuild items? I don't get how I should learn to use Timber. How do I get a hang of it, do you have a few links? If you tell me, after reading the entire Docs I'd get it, I'm glad to do that. The problem for me is, I don't even know how what I am looking for is called. Nowhere is mentioned, if I have to make all of these "items" myself, or if they are all prebuilt or whatever. I actually have no idea what is going on, and what I have to study.
    – frizzant
    Nov 6 at 7:50










  • I'm not actually using timber myself, i'm just using twig actually but it seems the new documentation can be found over here
    – DarkBee
    Nov 6 at 8:02











  • @DarkBee Those are the ones I was working with. My issue is that I can't just go and guess variables to output and hope for the best. Is there any chance you could help me with some questions a bit more in detail? I know this is dumb to ask for, however there isn't enough material on the web to help me - it's mainly this basic questions about the Variables etc. I'm trying to get them answered for more than a week now :(
    – frizzant
    Nov 6 at 8:21












up vote
0
down vote

favorite









up vote
0
down vote

favorite











For instance in the Timber Documentation we have lots of examples like the following:



% for item in menu.items %

post.author.name


Now the "item" and the "menu" etc. are all predefined, and nowhere defined by a user in the files (otherwise by my understanding Timber and TWIG would not make much sense).



What I do not understand is where I can find out a list these. In the Docs of Timber, there are a bunch of examples, then when I compare them to the Timber Starter Theme for Wordpress, I see a bunch of them, which aren't even mentioned in the documentations.



  1. Where do I find a list of all available items?

  2. What is the logic behind these items?









share|improve this question













For instance in the Timber Documentation we have lots of examples like the following:



% for item in menu.items %

post.author.name


Now the "item" and the "menu" etc. are all predefined, and nowhere defined by a user in the files (otherwise by my understanding Timber and TWIG would not make much sense).



What I do not understand is where I can find out a list these. In the Docs of Timber, there are a bunch of examples, then when I compare them to the Timber Starter Theme for Wordpress, I see a bunch of them, which aren't even mentioned in the documentations.



  1. Where do I find a list of all available items?

  2. What is the logic behind these items?






php wordpress twig timber






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 6 at 7:29









frizzant

3817




3817











  • To view all accessible variables u could do something like e.g. keys)
    – DarkBee
    Nov 6 at 7:43











  • @DarkBee So how come there is no list of prebuild items? I don't get how I should learn to use Timber. How do I get a hang of it, do you have a few links? If you tell me, after reading the entire Docs I'd get it, I'm glad to do that. The problem for me is, I don't even know how what I am looking for is called. Nowhere is mentioned, if I have to make all of these "items" myself, or if they are all prebuilt or whatever. I actually have no idea what is going on, and what I have to study.
    – frizzant
    Nov 6 at 7:50










  • I'm not actually using timber myself, i'm just using twig actually but it seems the new documentation can be found over here
    – DarkBee
    Nov 6 at 8:02











  • @DarkBee Those are the ones I was working with. My issue is that I can't just go and guess variables to output and hope for the best. Is there any chance you could help me with some questions a bit more in detail? I know this is dumb to ask for, however there isn't enough material on the web to help me - it's mainly this basic questions about the Variables etc. I'm trying to get them answered for more than a week now :(
    – frizzant
    Nov 6 at 8:21
















  • To view all accessible variables u could do something like e.g. keys)
    – DarkBee
    Nov 6 at 7:43











  • @DarkBee So how come there is no list of prebuild items? I don't get how I should learn to use Timber. How do I get a hang of it, do you have a few links? If you tell me, after reading the entire Docs I'd get it, I'm glad to do that. The problem for me is, I don't even know how what I am looking for is called. Nowhere is mentioned, if I have to make all of these "items" myself, or if they are all prebuilt or whatever. I actually have no idea what is going on, and what I have to study.
    – frizzant
    Nov 6 at 7:50










  • I'm not actually using timber myself, i'm just using twig actually but it seems the new documentation can be found over here
    – DarkBee
    Nov 6 at 8:02











  • @DarkBee Those are the ones I was working with. My issue is that I can't just go and guess variables to output and hope for the best. Is there any chance you could help me with some questions a bit more in detail? I know this is dumb to ask for, however there isn't enough material on the web to help me - it's mainly this basic questions about the Variables etc. I'm trying to get them answered for more than a week now :(
    – frizzant
    Nov 6 at 8:21















To view all accessible variables u could do something like e.g. keys)
– DarkBee
Nov 6 at 7:43





To view all accessible variables u could do something like e.g. keys)
– DarkBee
Nov 6 at 7:43













@DarkBee So how come there is no list of prebuild items? I don't get how I should learn to use Timber. How do I get a hang of it, do you have a few links? If you tell me, after reading the entire Docs I'd get it, I'm glad to do that. The problem for me is, I don't even know how what I am looking for is called. Nowhere is mentioned, if I have to make all of these "items" myself, or if they are all prebuilt or whatever. I actually have no idea what is going on, and what I have to study.
– frizzant
Nov 6 at 7:50




@DarkBee So how come there is no list of prebuild items? I don't get how I should learn to use Timber. How do I get a hang of it, do you have a few links? If you tell me, after reading the entire Docs I'd get it, I'm glad to do that. The problem for me is, I don't even know how what I am looking for is called. Nowhere is mentioned, if I have to make all of these "items" myself, or if they are all prebuilt or whatever. I actually have no idea what is going on, and what I have to study.
– frizzant
Nov 6 at 7:50












I'm not actually using timber myself, i'm just using twig actually but it seems the new documentation can be found over here
– DarkBee
Nov 6 at 8:02





I'm not actually using timber myself, i'm just using twig actually but it seems the new documentation can be found over here
– DarkBee
Nov 6 at 8:02













@DarkBee Those are the ones I was working with. My issue is that I can't just go and guess variables to output and hope for the best. Is there any chance you could help me with some questions a bit more in detail? I know this is dumb to ask for, however there isn't enough material on the web to help me - it's mainly this basic questions about the Variables etc. I'm trying to get them answered for more than a week now :(
– frizzant
Nov 6 at 8:21




@DarkBee Those are the ones I was working with. My issue is that I can't just go and guess variables to output and hope for the best. Is there any chance you could help me with some questions a bit more in detail? I know this is dumb to ask for, however there isn't enough material on the web to help me - it's mainly this basic questions about the Variables etc. I'm trying to get them answered for more than a week now :(
– frizzant
Nov 6 at 8:21












1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










Don’t feel dumb, because you’re not! We’ve all been there. I had the same questions, when I started out with Timber. We’re trying to improve the documentation constantly, so questions like these help us to find out what we can do better 👍.



Whenever you see a variable in Twig, it can actually come from a couple of different places:



Variables from the global context



There’s a filter that most of us use to make a variable globally available whenever you set up your context through Timber::get_context(). When you see % for item in menu.items %, then it’s probably from the section of the docs about «Setting up a menu globally». I have to admit that we explain the filter through this example only, which is not ideal. But we’re changing this. In the next version of Timber, we try to explain the global context better (make sure to only read the section about the global context, because the part about «Template Contexts» describes functionality that is not available yet.)



Variables from the template



Consider the following example:



$context = Timber::get_context();
$context['post'] = new TimberPost();

Timber::render( 'single.twig', $context );


Here you set up your context through Timber::get_context(). When you use Timber::get_context(), you’ll get a bunch of variables that make sense globally, but not for every template.



The $context variable is an array, holding all the variables you want to pass to your Twig template, in this case single.twig. When can add our own variables, like in the example above, where we add post that hold a TimberPost object of the currently displayed post.



Variables from Timber’s classes



In the template, when you see post.author.name , then author can be different things:



  • A property of the TimberPost object that holds a value. These are all the variables that you’d see when you do dump(post) .

  • A method of the TimberPost object, that will be excecuted. This might be confusing at first, because in PHP, you always need to add braces to call a function, but in Twig, you don’t need to. When you call $post->author() in PHP, you would use post.author in Twig. To see a list of all the methods that are available for TimberPost, you need to look into the Reference section for TimberPost in the docs.

So if you would write the example post.author.name in PHP, it would look like this:



$post->author()->name()


So author is a method of TimberPost, which returns a TimberUser object. The TimberUser object has a method called name, which returns «the human-friendly name of the user».



But! When you just look at post.author.name , it could also be a multi-dimensional array that you defined yourself:



$context['post'] = array(
'author' => array(
'name' => 'Tom Riddle',
),
);


You wouldn’t know that just from looking at it in Twig.



Variables from the Twig syntax



When you see % for item in menu.items %, then you’re looping over the variable menu.items. The variable menu probably comes from the global context (a TimberMenu object), and items is a property of this object. The item variable is a new variable that is created to access the current loop item in the for loop. In this example, it’s the current menu item. You can choose any name for item you want.



Variables from includes



You can pass down a variable in Twig through the include statement. For example, if you defined post through your template file and wanted to use a different name in the template that you include, you could use it like this:



% include 'teaser.twig' with teaser: post %



Coming back to your specific questions:




  1. Where do I find a list of all available items?

  2. What is the logic behind these items?



I’m afraid there isn’t a definitive list, because what a variable is can be very dynamic. It’s mostly a combination of the global context, variables you set from the template, methods and properties from Timber’s classes as well as variables you define yourself in Twig.



If you have more question, add the to this answer as comments and I can update this answer accordingly.






share|improve this answer




















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53167484%2ftimber-twig-for-wordpress-questions-about-some-basics%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote



    accepted










    Don’t feel dumb, because you’re not! We’ve all been there. I had the same questions, when I started out with Timber. We’re trying to improve the documentation constantly, so questions like these help us to find out what we can do better 👍.



    Whenever you see a variable in Twig, it can actually come from a couple of different places:



    Variables from the global context



    There’s a filter that most of us use to make a variable globally available whenever you set up your context through Timber::get_context(). When you see % for item in menu.items %, then it’s probably from the section of the docs about «Setting up a menu globally». I have to admit that we explain the filter through this example only, which is not ideal. But we’re changing this. In the next version of Timber, we try to explain the global context better (make sure to only read the section about the global context, because the part about «Template Contexts» describes functionality that is not available yet.)



    Variables from the template



    Consider the following example:



    $context = Timber::get_context();
    $context['post'] = new TimberPost();

    Timber::render( 'single.twig', $context );


    Here you set up your context through Timber::get_context(). When you use Timber::get_context(), you’ll get a bunch of variables that make sense globally, but not for every template.



    The $context variable is an array, holding all the variables you want to pass to your Twig template, in this case single.twig. When can add our own variables, like in the example above, where we add post that hold a TimberPost object of the currently displayed post.



    Variables from Timber’s classes



    In the template, when you see post.author.name , then author can be different things:



    • A property of the TimberPost object that holds a value. These are all the variables that you’d see when you do dump(post) .

    • A method of the TimberPost object, that will be excecuted. This might be confusing at first, because in PHP, you always need to add braces to call a function, but in Twig, you don’t need to. When you call $post->author() in PHP, you would use post.author in Twig. To see a list of all the methods that are available for TimberPost, you need to look into the Reference section for TimberPost in the docs.

    So if you would write the example post.author.name in PHP, it would look like this:



    $post->author()->name()


    So author is a method of TimberPost, which returns a TimberUser object. The TimberUser object has a method called name, which returns «the human-friendly name of the user».



    But! When you just look at post.author.name , it could also be a multi-dimensional array that you defined yourself:



    $context['post'] = array(
    'author' => array(
    'name' => 'Tom Riddle',
    ),
    );


    You wouldn’t know that just from looking at it in Twig.



    Variables from the Twig syntax



    When you see % for item in menu.items %, then you’re looping over the variable menu.items. The variable menu probably comes from the global context (a TimberMenu object), and items is a property of this object. The item variable is a new variable that is created to access the current loop item in the for loop. In this example, it’s the current menu item. You can choose any name for item you want.



    Variables from includes



    You can pass down a variable in Twig through the include statement. For example, if you defined post through your template file and wanted to use a different name in the template that you include, you could use it like this:



    % include 'teaser.twig' with teaser: post %



    Coming back to your specific questions:




    1. Where do I find a list of all available items?

    2. What is the logic behind these items?



    I’m afraid there isn’t a definitive list, because what a variable is can be very dynamic. It’s mostly a combination of the global context, variables you set from the template, methods and properties from Timber’s classes as well as variables you define yourself in Twig.



    If you have more question, add the to this answer as comments and I can update this answer accordingly.






    share|improve this answer
























      up vote
      2
      down vote



      accepted










      Don’t feel dumb, because you’re not! We’ve all been there. I had the same questions, when I started out with Timber. We’re trying to improve the documentation constantly, so questions like these help us to find out what we can do better 👍.



      Whenever you see a variable in Twig, it can actually come from a couple of different places:



      Variables from the global context



      There’s a filter that most of us use to make a variable globally available whenever you set up your context through Timber::get_context(). When you see % for item in menu.items %, then it’s probably from the section of the docs about «Setting up a menu globally». I have to admit that we explain the filter through this example only, which is not ideal. But we’re changing this. In the next version of Timber, we try to explain the global context better (make sure to only read the section about the global context, because the part about «Template Contexts» describes functionality that is not available yet.)



      Variables from the template



      Consider the following example:



      $context = Timber::get_context();
      $context['post'] = new TimberPost();

      Timber::render( 'single.twig', $context );


      Here you set up your context through Timber::get_context(). When you use Timber::get_context(), you’ll get a bunch of variables that make sense globally, but not for every template.



      The $context variable is an array, holding all the variables you want to pass to your Twig template, in this case single.twig. When can add our own variables, like in the example above, where we add post that hold a TimberPost object of the currently displayed post.



      Variables from Timber’s classes



      In the template, when you see post.author.name , then author can be different things:



      • A property of the TimberPost object that holds a value. These are all the variables that you’d see when you do dump(post) .

      • A method of the TimberPost object, that will be excecuted. This might be confusing at first, because in PHP, you always need to add braces to call a function, but in Twig, you don’t need to. When you call $post->author() in PHP, you would use post.author in Twig. To see a list of all the methods that are available for TimberPost, you need to look into the Reference section for TimberPost in the docs.

      So if you would write the example post.author.name in PHP, it would look like this:



      $post->author()->name()


      So author is a method of TimberPost, which returns a TimberUser object. The TimberUser object has a method called name, which returns «the human-friendly name of the user».



      But! When you just look at post.author.name , it could also be a multi-dimensional array that you defined yourself:



      $context['post'] = array(
      'author' => array(
      'name' => 'Tom Riddle',
      ),
      );


      You wouldn’t know that just from looking at it in Twig.



      Variables from the Twig syntax



      When you see % for item in menu.items %, then you’re looping over the variable menu.items. The variable menu probably comes from the global context (a TimberMenu object), and items is a property of this object. The item variable is a new variable that is created to access the current loop item in the for loop. In this example, it’s the current menu item. You can choose any name for item you want.



      Variables from includes



      You can pass down a variable in Twig through the include statement. For example, if you defined post through your template file and wanted to use a different name in the template that you include, you could use it like this:



      % include 'teaser.twig' with teaser: post %



      Coming back to your specific questions:




      1. Where do I find a list of all available items?

      2. What is the logic behind these items?



      I’m afraid there isn’t a definitive list, because what a variable is can be very dynamic. It’s mostly a combination of the global context, variables you set from the template, methods and properties from Timber’s classes as well as variables you define yourself in Twig.



      If you have more question, add the to this answer as comments and I can update this answer accordingly.






      share|improve this answer






















        up vote
        2
        down vote



        accepted







        up vote
        2
        down vote



        accepted






        Don’t feel dumb, because you’re not! We’ve all been there. I had the same questions, when I started out with Timber. We’re trying to improve the documentation constantly, so questions like these help us to find out what we can do better 👍.



        Whenever you see a variable in Twig, it can actually come from a couple of different places:



        Variables from the global context



        There’s a filter that most of us use to make a variable globally available whenever you set up your context through Timber::get_context(). When you see % for item in menu.items %, then it’s probably from the section of the docs about «Setting up a menu globally». I have to admit that we explain the filter through this example only, which is not ideal. But we’re changing this. In the next version of Timber, we try to explain the global context better (make sure to only read the section about the global context, because the part about «Template Contexts» describes functionality that is not available yet.)



        Variables from the template



        Consider the following example:



        $context = Timber::get_context();
        $context['post'] = new TimberPost();

        Timber::render( 'single.twig', $context );


        Here you set up your context through Timber::get_context(). When you use Timber::get_context(), you’ll get a bunch of variables that make sense globally, but not for every template.



        The $context variable is an array, holding all the variables you want to pass to your Twig template, in this case single.twig. When can add our own variables, like in the example above, where we add post that hold a TimberPost object of the currently displayed post.



        Variables from Timber’s classes



        In the template, when you see post.author.name , then author can be different things:



        • A property of the TimberPost object that holds a value. These are all the variables that you’d see when you do dump(post) .

        • A method of the TimberPost object, that will be excecuted. This might be confusing at first, because in PHP, you always need to add braces to call a function, but in Twig, you don’t need to. When you call $post->author() in PHP, you would use post.author in Twig. To see a list of all the methods that are available for TimberPost, you need to look into the Reference section for TimberPost in the docs.

        So if you would write the example post.author.name in PHP, it would look like this:



        $post->author()->name()


        So author is a method of TimberPost, which returns a TimberUser object. The TimberUser object has a method called name, which returns «the human-friendly name of the user».



        But! When you just look at post.author.name , it could also be a multi-dimensional array that you defined yourself:



        $context['post'] = array(
        'author' => array(
        'name' => 'Tom Riddle',
        ),
        );


        You wouldn’t know that just from looking at it in Twig.



        Variables from the Twig syntax



        When you see % for item in menu.items %, then you’re looping over the variable menu.items. The variable menu probably comes from the global context (a TimberMenu object), and items is a property of this object. The item variable is a new variable that is created to access the current loop item in the for loop. In this example, it’s the current menu item. You can choose any name for item you want.



        Variables from includes



        You can pass down a variable in Twig through the include statement. For example, if you defined post through your template file and wanted to use a different name in the template that you include, you could use it like this:



        % include 'teaser.twig' with teaser: post %



        Coming back to your specific questions:




        1. Where do I find a list of all available items?

        2. What is the logic behind these items?



        I’m afraid there isn’t a definitive list, because what a variable is can be very dynamic. It’s mostly a combination of the global context, variables you set from the template, methods and properties from Timber’s classes as well as variables you define yourself in Twig.



        If you have more question, add the to this answer as comments and I can update this answer accordingly.






        share|improve this answer












        Don’t feel dumb, because you’re not! We’ve all been there. I had the same questions, when I started out with Timber. We’re trying to improve the documentation constantly, so questions like these help us to find out what we can do better 👍.



        Whenever you see a variable in Twig, it can actually come from a couple of different places:



        Variables from the global context



        There’s a filter that most of us use to make a variable globally available whenever you set up your context through Timber::get_context(). When you see % for item in menu.items %, then it’s probably from the section of the docs about «Setting up a menu globally». I have to admit that we explain the filter through this example only, which is not ideal. But we’re changing this. In the next version of Timber, we try to explain the global context better (make sure to only read the section about the global context, because the part about «Template Contexts» describes functionality that is not available yet.)



        Variables from the template



        Consider the following example:



        $context = Timber::get_context();
        $context['post'] = new TimberPost();

        Timber::render( 'single.twig', $context );


        Here you set up your context through Timber::get_context(). When you use Timber::get_context(), you’ll get a bunch of variables that make sense globally, but not for every template.



        The $context variable is an array, holding all the variables you want to pass to your Twig template, in this case single.twig. When can add our own variables, like in the example above, where we add post that hold a TimberPost object of the currently displayed post.



        Variables from Timber’s classes



        In the template, when you see post.author.name , then author can be different things:



        • A property of the TimberPost object that holds a value. These are all the variables that you’d see when you do dump(post) .

        • A method of the TimberPost object, that will be excecuted. This might be confusing at first, because in PHP, you always need to add braces to call a function, but in Twig, you don’t need to. When you call $post->author() in PHP, you would use post.author in Twig. To see a list of all the methods that are available for TimberPost, you need to look into the Reference section for TimberPost in the docs.

        So if you would write the example post.author.name in PHP, it would look like this:



        $post->author()->name()


        So author is a method of TimberPost, which returns a TimberUser object. The TimberUser object has a method called name, which returns «the human-friendly name of the user».



        But! When you just look at post.author.name , it could also be a multi-dimensional array that you defined yourself:



        $context['post'] = array(
        'author' => array(
        'name' => 'Tom Riddle',
        ),
        );


        You wouldn’t know that just from looking at it in Twig.



        Variables from the Twig syntax



        When you see % for item in menu.items %, then you’re looping over the variable menu.items. The variable menu probably comes from the global context (a TimberMenu object), and items is a property of this object. The item variable is a new variable that is created to access the current loop item in the for loop. In this example, it’s the current menu item. You can choose any name for item you want.



        Variables from includes



        You can pass down a variable in Twig through the include statement. For example, if you defined post through your template file and wanted to use a different name in the template that you include, you could use it like this:



        % include 'teaser.twig' with teaser: post %



        Coming back to your specific questions:




        1. Where do I find a list of all available items?

        2. What is the logic behind these items?



        I’m afraid there isn’t a definitive list, because what a variable is can be very dynamic. It’s mostly a combination of the global context, variables you set from the template, methods and properties from Timber’s classes as well as variables you define yourself in Twig.



        If you have more question, add the to this answer as comments and I can update this answer accordingly.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 11 at 11:57









        Gchtr

        1,22411020




        1,22411020



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53167484%2ftimber-twig-for-wordpress-questions-about-some-basics%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            How to read a connectionString WITH PROVIDER in .NET Core?

            Node.js Script on GitHub Pages or Amazon S3

            Museum of Modern and Contemporary Art of Trento and Rovereto