Jump to content

Twig template variables


rink.attendant.6
 Share

Recommended Posts

I'm not sure how many (or if any) of you are familiar with the Twig templating system, I'm just starting off with it (might as well give it a try I suppose, Smarty seemed to be overkill). Everything has been going well so far, except I'm a bit confused as to whether I'm supposed to have the entire contents of my page in one variable. In the example in the documentation here: http://twig.sensiolabs.org/doc/templates.html , under "My Webpage" it has {{ a_variable }}, which is where all the content goes. My template is similar to that, with a header, sidebar and footer. I'm just wondering whether I'm supposed to put all of the HTML of the main content into one variable and pass it through like that or is there something I'm missing? I plan to use one page to parse everything (the "controller"), just like how WordPress uses one page to display all of the public area of a site through fancy URL rewrites.

Link to comment
Share on other sites

I'm just wondering whether I'm supposed to put all of the HTML of the main content into one variable and pass it through like that or is there something I'm missing?
That's how most template engines operate, yes - a generic code base (typically including only the minimal HTML), with further specifics along the way, with the head and body contents typically being the first ones to be considered "more specific". The tricky bit is that the variable itself should be generated via the template engine (Twig in this case).Either that, or the engine needs to somehow allow you to pass control to a different template based on the value of a variable (which would be fixed from the start). The page you link to talks about an "extends" instruction, which extends a base template and can provide input for blocks. Sounds like what you need.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...