Welcome Guest, Not a member yet? Register   Sign In
Does the Template Parser class supports inheritance like Django's template?
#1

[eluser]tlam[/eluser]
I was testing Django's template's inheritance feature and noticed how useful it is. Does anyone know if it's possible to do something similar with CI's Template Parser? Here's what I was referring to for Django, lifted from http://docs.djangoproject.com/en/dev/top...lates/#id1:

The following is base.html
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html &gt;
&lt;head&gt;
    &lt;link rel="stylesheet" href="style.css" /&gt;
    &lt;title&gt;{% block title %}My amazing site{% endblock %}&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
    <div id="sidebar">
        {% block sidebar %}
        <ul>
            <li><a href="/">Home</a></li>
            <li><a href="/blog/">Blog</a></li>
        </ul>
        {% endblock %}
    </div>

    <div id="content">
        {% block content %}{% endblock %}
    </div>
&lt;/body&gt;
&lt;/html&gt;

The sub template:
Code:
{% extends "base.html" %}

{% block title %}My amazing blog{% endblock %}

{% block content %}
{% for entry in blog_entries %}
    <h2>{{ entry.title }}</h2>
    <p>{{ entry.body }}</p>
{% endfor %}
{% endblock %}
#2

[eluser]Dam1an[/eluser]
I havn't seen this functionality, and very much doubt its exists (at least not nativly) as the CI template library as meant to be light weight, not a full blown template engine
#3

[eluser]bretticus[/eluser]
[quote author="tlam" date="1240278488"]I was testing Django's template's inheritance feature and noticed how useful it is. Does anyone know if it's possible to do something similar with CI's Template Parser? [/quote]

Actually, CI does have the ability to parse templates and it would probably be trivial to write in the ability to include content from another view using this templating. If you don't want to venture there. PHP Smarty did this long before django Smile Here is a tutorial using smarty and CI.

EDIT: Ok, on a second look, maybe not so trivial with the CI library. However, this feature *should* be available with Smarty.
#4

[eluser]arshaw[/eluser]
hey tlam, i just published an open source project to do such a thing. it is PHP Template Inheritance. it lets you do it in native php, without smarty or any other template parser. it has a really clean syntax. hope it is useful to you.
#5

[eluser]Davide Bellini[/eluser]
Take a look to Twig :
http://www.twig-project.org/

You can integrate the library in CI.




Theme © iAndrew 2016 - Forum software by © MyBB