Skip to content

Instantly share code, notes, and snippets.

@lozadaOmr
Last active August 29, 2015 14:19
Show Gist options
  • Save lozadaOmr/5bad188baaff2b285099 to your computer and use it in GitHub Desktop.
Save lozadaOmr/5bad188baaff2b285099 to your computer and use it in GitHub Desktop.
Some notes on learning Jinja Template; making a note on its equivalent to Blade

Extending a master template

Jinja - {% extends "base.html" %}
Blade - @extends('templates.blade')

Including a section

Jinja - {% include 'navigation.html' %}
Blade - @include('navigation')

Interpolating Variable

Jinja - {{ var }}
Blade - {{ $var }}

For Loops

Jinja -

{% for item in navigation %}
    <li><a href="{{ item.href }}">{{ item.caption }}</a></li>
{% endfor %}

Blade -

@foreach ($users as $user)
    <p>This is user {{ $user->id }}</p>
@endforeach

Template Inheritance

Jinja -

# base.html
{% block content %}{% endblock %}

# nav.html
{% extends "base.html" %}
{% block content %}
    <h1>Hi, {{ user.nickname }}!</h1>
{% endblock %}

Blade -

# base.blade.php
@yield('nav')

# nav.blade.php
@section('base')
    <h1>HI, {{ user_nickname }}!</h1>
@stop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment