Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Question about block inheritance with multiple parents defining the same block(s) ( my-post extends post extends base )
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Beau Simensen  
View profile  
 More options Nov 15 2012, 11:32 am
From: Beau Simensen <simen...@gmail.com>
Date: Thu, 15 Nov 2012 08:32:51 -0800 (PST)
Local: Thurs, Nov 15 2012 11:32 am
Subject: Question about block inheritance with multiple parents defining the same block(s) ( my-post extends post extends base )

I'm trying to figure out the best way to standardize on a block for all
templates ( {% block content %} ) but allow for being able to drop in a
layer between the base template and the outermost template. The use case
would be for a blog site where the static pages all extend base.twig but
for certain classes of pages you might want to wrap content in a consistent
way, like for posts. What I'm doing in my base.twig currently is:

{% block content_wrapper %}{% block content %}{% endblock %}{% endblock %}

All of my edge templates can just use {% block content %} to inject their
content, and can either extend base.twig or something like post.twig. In
that case, post.twig looks like:

{% block content_wrapper %}<div class="custom-things post-stuff">{% block
content %}{% endblock %}</div>{% endblock %}

Which is fine, but doesn't feel very elegant. I thought it would be
something like parent, but child. But given how this is all based on PHP
classes, I don't really know if I'd know how to do this with objects
directly so maybe it isn't possible? Is there a way to do something like
this natively that I completely missed?

Here is my naive expectation on how this should work. I understand that it
doesn't, but this is the first thing I tried before I really thought about
what I was doing. :) It might better show what I'm hoping to accomplish.

*base.twig*

<html>
{% block content %}{% endblock %}
</html>

*post.twig*

{% extend "base.twig" %}
{% block content %}
  <div class="post">
  <h1>{{ title }}</h1>
  {% block content %}{% endblock %}
{% endblock %}

*index.twig*

{% extend "base.twig" %}
{% block content %}
Index Content.
{% endblock %}

*some-post.twig*

{% extend "post.twig" %}
{% set title = 'This is Some Post' %}
{% block content %}
This is Some Post content.
{% endblock %}

*index.html (rendered index.twig)*

<html>
Index Content.
</html>

*some-post.html (rendered some-post.twig)*

<html>
  <div class="post">
  <h1>This is Some Post</h1>
  This is Some Post content.
</html>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »