How to Use Jinja Templates and Variables on RebelMouse

Understanding Our Detailed Customization

Jinja Template Syntax: Where to Use and Why

If you need to pass in post variables to third-party or custom-written JavaScript, Jinja variables are a perfect solution.

These are often used for passing editorial tags, sections, and custom fields into ad tags. Click here for more information.

Jinja variables are available to use in any custom HTML element.


Most Commonly Used Jinja Variables

  • Basename: {{post.basename}}
    • Available only on post pages
  • Post URL: {{post.post_url}}
    • Available only on post pages
  • Post Sections: {{sections}}
    • Available only on post pages
  • Post Primary Section Name: {{post.primary_section_name}}
    • Available only on post pages if primary section is set explicitly
  • Post Tags: {{tags}}
    • Available only on post pages
  • Section Page: {{subpage.title}}
  • Created Date: {{created_date}}
  • Current Year: {{libs.datetime.datetime.utcnow().year}}
  • Created Timestamp: {{Created_tse}}
  • Sub Page URL: {{subpage_url}}
    • Available only on section pages
  • Primary Section Slug: {{primary_section_slug}:}
  • Primary Section URL {{Primary_section_url}}

What Post Variables Are Available?

You can view all variables here. There's also a simple way to view all variables if you add the JSONView extension to your Google Chrome browser. With it, you can clearly view a post's JSON data, as shown in this example. Any of your own articles will follow a similar format.

Example: Spot.IM Integration

In this example, Spot.IM is integrated using Jinja template variables to pass a Post ID and BaseName into the tags.

    <div data-spot-id="CLIENT_ID" data-spotim-module="recirculation"></div>
<script async="" client_id="" https:="" recirculation.spot.im="" rel="noopener noreferrer" spot="" src="<a%20href=" target="_blank"><a href="<a href=" <a="" target="_blank" rel="noopener noreferrer"><a href="<a href="<a href="<a href="<a href="<a href="<a href="<a href="https://recirculation.spot.im/spot/CLIENT_ID" target="_blank" rel="noopener noreferrer">https://recirculation.spot.im/spot/CLIENT_ID</a>" target="_blank" rel="noopener noreferrer">https://recirculation.spot.im/spot/CLIENT_ID</a>" target="_blank" rel="noopener noreferrer">https://recirculation.spot.im/spot/CLIENT_ID</a>" target="_blank" rel="noopener noreferrer">https://recirculation.spot.im/spot/CLIENT_ID</a>" target="_blank" rel="noopener noreferrer">https://recirculation.spot.im/spot/CLIENT_ID</a>" target="_blank" rel="noopener noreferrer">https://recirculation.spot.im/spot/CLIENT_ID</a>" target="_blank" rel="noopener noreferrer">https://recirculation.spot.im/spot/CLIENT_ID</a>" target="_blank" rel="noopener noreferrer">https://recirculation.spot.im/spot/CLIENT_ID</a></a>" target="_blank" rel="noopener noreferrer"><a href="<a href=" https:="" recirculation.spot.im="" spot="" client_id"="" target="_blank" rel="noopener noreferrer">https://recirculation.spot.im/spot/CLIENT_ID</a>" target="_blank" rel="noopener noreferrer"><a href="<a href=" https:="" recirculation.spot.im="" spot="" client_id"="" target="_blank" rel="noopener noreferrer">https://recirculation.spot.im/spot/CLIENT_ID</a>" target="_blank" rel="noopener noreferrer"><a href="<a href=" https:="" recirculation.spot.im="" spot="" client_id"="" target="_blank" rel="noopener noreferrer">https://recirculation.spot.im/spot/CLIENT_ID</a>" target="_blank" rel="noopener noreferrer"><a href="<a href=" https:="" recirculation.spot.im="" spot="" client_id"="" target="_blank" rel="noopener noreferrer">https://recirculation.spot.im/spot/CLIENT_ID</a>" target="_blank" rel="noopener noreferrer"><a href="<a href=" https:="" recirculation.spot.im="" spot="" client_id"="" target="_blank" rel="noopener noreferrer">https://recirculation.spot.im/spot/CLIENT_ID</a>" target="_blank" rel="noopener noreferrer">https://recirculation.spot.im/spot/CLIENT_ID" target="_blank" rel="noopener noreferrer">https://recirculation.spot.im/spot/CLIENT_ID"></script>
<script async="" client_id="" https:="" launcher.spot.im="" rel="noopener noreferrer" spot="" src="<a%20href=" target="_blank"><a href="<a href=" <a="" target="_blank" rel="noopener noreferrer"><a href="<a href="<a href="<a href="<a href="<a href="<a href="<a href="https://launcher.spot.im/spot/CLIENT_ID" target="_blank" rel="noopener noreferrer">https://launcher.spot.im/spot/CLIENT_ID</a>" target="_blank" rel="noopener noreferrer">https://launcher.spot.im/spot/CLIENT_ID</a>" target="_blank" rel="noopener noreferrer">https://launcher.spot.im/spot/CLIENT_ID</a>" target="_blank" rel="noopener noreferrer">https://launcher.spot.im/spot/CLIENT_ID</a>" target="_blank" rel="noopener noreferrer">https://launcher.spot.im/spot/CLIENT_ID</a>" target="_blank" rel="noopener noreferrer">https://launcher.spot.im/spot/CLIENT_ID</a>" target="_blank" rel="noopener noreferrer">https://launcher.spot.im/spot/CLIENT_ID</a>" target="_blank" rel="noopener noreferrer">https://launcher.spot.im/spot/CLIENT_ID</a></a>" target="_blank" rel="noopener noreferrer"><a href="<a href=" https:="" launcher.spot.im="" spot="" client_id"="" target="_blank" rel="noopener noreferrer">https://launcher.spot.im/spot/CLIENT_ID</a>" target="_blank" rel="noopener noreferrer"><a href="<a href=" https:="" launcher.spot.im="" spot="" client_id"="" target="_blank" rel="noopener noreferrer">https://launcher.spot.im/spot/CLIENT_ID</a>" target="_blank" rel="noopener noreferrer"><a href="<a href=" https:="" launcher.spot.im="" spot="" client_id"="" target="_blank" rel="noopener noreferrer">https://launcher.spot.im/spot/CLIENT_ID</a>" target="_blank" rel="noopener noreferrer"><a href="<a href=" https:="" launcher.spot.im="" spot="" client_id"="" target="_blank" rel="noopener noreferrer">https://launcher.spot.im/spot/CLIENT_ID</a>" target="_blank" rel="noopener noreferrer"><a href="<a href=" https:="" launcher.spot.im="" spot="" client_id"="" target="_blank" rel="noopener noreferrer">https://launcher.spot.im/spot/CLIENT_ID</a>" target="_blank" rel="noopener noreferrer">https://launcher.spot.im/spot/CLIENT_ID" target="_blank" rel="noopener noreferrer">https://launcher.spot.im/spot/CLIENT_ID" id="spotim"
    data-spotim-module="spotim-launcher"
    data-post-id="{{post.basename}}"
    data-post-url="{{post.post_url}}"></script>

Insert Variables in Our Layout & Design Tool

Users can click on any element in our Layout & Design tool and select a Jinja variable to insert. Here's an example on a Heading element:

Advanced Usage: Jinja Tag and Post Context Variables

We've exposed the most popular variables used as simple {{post.something}} variables, but sometimes you may need to access a variable that's not exposed. You can use the aforementioned JSONView Google Chrome extension to look at your own JSON and access any of those variables. But it's important to reference the context correctly. Here's an example:

Post Variables

Here are most of our post variables located in one place. The list contains some variables you can't see in JSON. For example, post.attrs (goes from XML to our Layout & Design tool) and post.is_mobile.

Using Variables to Control OG Tags

In our Layout & Design tool, you have the ability to create variable overrides. This is helpful when having to set the Open Graph (OG) tags in a section or post page, or in the <head> tag of a page.You can easily find all variables available by inserting the Variable Override element:

Then choose the one you need from the drop-down picklist:

We offer support for:

  • OG Image
  • OG Video
  • OG URL
  • OG Page Type
  • Facebook Share Title
  • Facebook Share Description
  • Site Language

Advanced Usage: Using Jinja With Conditions

For using conditions, loops, setting values, splitting, and slicing with Jinja, you should create a new Jinja element. This element should only be used by developers with high levels of technical skill.

First, this element needs to be added from code:

By adding the code, you'll create the element:

Once the element is created, you can start adding your code.

Basic Example Code:

{% if context.post.roar_specific_data.breadcrumb_title %}
    {{context.post.roar_specific_data.breadcrumb_title}}
{% else %}
   {{context.post.headline}}
{% endif %}

You can also loop through tags or check if a particular value is present. Here's a code example:

{% if context.post.original_user_subsite.roar_specific_data %}
<div class="parner_container">
  <div class="partner_headline">More From 
  <a class="partner_site_name">{{context.post.original_user_subsite.roar_specific_data.site_name}}</a>
  </div>
  {% for posts in context.post.original_user_subsite.roar_specific_data.posts %}
  <div class="partner_posts"><a href="{{posts.url}}">{{posts.headline}} </a></div>
  {% endfor %}
  <div class="partner_site_info">This article originally appeared on 
    <a href="{{context.post.original_user_subsite.roar_specific_data.site_url}}">
    {{context.post.original_user_subsite.roar_specific_data.site_name}} </a>
  </div>

The list of these values can be found in the console, and you can find it by searching for rblms.require('bootstrap'). This is where you'll find the whole context list.

Remember, Jinja is a template engine that puts values in the places you add them to. This means it's scope dependent. So if you set one value based on a specific scope, you need to consider how it'll be displayed elsewhere.

If you have any questions about Jinja variables, email support@rebelmouse.com.

Why RebelMouse Is the Best Content Marketing Platform

RebelMouse is a unique platform and company. The company was founded on the vision that media companies would need an always-modern solution to thrive in the new connected internet, and that brands would have to behave like new media companies and use the same platforms.

Keep reading... Show less

Why Premium Creative Agencies and CTOs Choose to Develop on RebelMouse vs. WordPress and Drupal

The Intersection of Design and Development: Where Your Clients Thrive

We started RebelMouse seven years ago knowing that there was a fundamental design flaw in the world of traditional CMSs: Every instance, on every platform, had to be updated independently. It's similar to an era when users had to manage their own Microsoft Exchange Server for email. The costs of managing, maintaining, and iterating on a CMS to keep it awesome and world class is typically a $10 million-a-year endeavor. But even then, these cost-prohibitive CMSs are still behind the times.

Keep reading... Show less

Native Multivariate Testing at Scale With RebelMouse

What Differentiates Our Approach

There are many popular tools that allow you to perform experiments and A/B tests on your users — primarily Google Chrome Experiments and Optimizely. But all of these solutions are JavaScript additions to your web page that sidestep the problem of old, outdated, and clumsy CMSs. These solutions work by calling on a third-party JavaScript library that rewrites a page after it's rendered. This approach adds extra page weight and creates strange user experiences due to having to wait for everything to load and be rewritten on the fly.

At RebelMouse, we've solved this in a very elegant way. At the core level of our platform, we can natively render different layouts and track the exact differences in performance when comparing a test to your other layouts.

Keep reading... Show less

Modern E-Commerce: Blur the Line Between Content and Design

Create Modular + Reusable Design Patterns on RebelMouse

Content saturation is an industry-wide problem, and the e-commerce space is no exception given that it's filled with big brands, small Etsy stores, and everyone in between all fighting for similar audiences. The best way to fight this symptom is to understand your audience and provide them with what they want.

Keep reading... Show less

Instagram-style E-commerce Features on RebelMouse

Revolutionizing e-commerce on RebelMouse

Whether you're a brand with a blog or a media company with a site, driving purchasing behavior and building an audience that uses your content to find things they love to buy is vital. We're very proud to have built out the same functionality that everyone is now used to on Instagram, with layovers on images that lead to products with attribution.

Keep reading... Show less

Building Premium Communities and User Journeys on RebelMouse

RebelMouse is much more than just a replacement for a traditional CMS. Our platform is a tremendous community-building experience. Today's social ecosystem has given us a seemingly limitless number of premium creators who understand how to create gorgeous and relevant content that drives the growth of their own audiences. These creators and influencers are either experts in certain topics, or heavily engaged in targeted content that drives their interests. They're not only consuming the content they're passionate about, but they're contributing to the conversation, too. The new role of the editor is not just to cover the most important topics and people around their expertise, but also to invite those preferred influencers into their community and get them to participate in creating premium content.

Keep reading... Show less

Dynamic Voting: Grow Traffic and Engagement Organically

Help your audience find its voice.

Creating quality content is no longer on marketers alone. We live in a universe of creators who are willing to not only consume content that resonates, but play a role in the creation, promotion, and conversations surrounding it.

Since the start of RebelMouse, we've been on a journey to create dynamic media that is easier for content creators to curate and amplify on social. It's why we've built an online engagement platform centered around the power of communities that thrive naturally in the digital ecosystem.

Keep reading... Show less

How to Monetize Your Website in Today’s Publishing Environment

In order to define distributive publishing, we have to ask the following question: If you have quality content, but nobody sees it, does it even exist? The answer is no, because your content needs to be supported in a way that lets it move seamlessly across all channels, especially site, search, and social. But let's take this question a step further: If you can't monetize your content to generate the support it needs, how do you create quality content in the first place?

Keep reading... Show less

Making Sense of PageSpeed Insights and Core Web Vitals

Page speed and Core Web Vitals are an important piece of the SEO puzzle. Having a quick load time and passing Core Web Vitals are important factors in Google's search ranking and results. But there are multiple ways of testing your speed and vitals, and it can get very confusing to try and understand the results since different measuring tools can result in different scores.

Keep reading... Show less

Reach New Revenue Heights With RebelMouse’s Boost Spot Placement

Authentic sponsored content piques user interest and yields high rewards

Monetization has to be multifaceted. Publishers must deliver a site experience that makes the user a top priority without sacrificing the ability to generate ad revenue. After all, readers are no longer going to put up with irritating ad experiences that slow down their consumption of content. And since publishers can't rely on a few viral moments to make ends meet, successful ad campaigns must feel genuine and produce consistent returns to be effective.

The need for smart, sticky monetization methods is nothing new, but publishers and marketers alike are starting to perfect the modern ad experience better than ever before. This success is due in part to the increased use of sponsored content.

Sponsored content is the creation of content for a brand by a publisher — whether it's an article, video, listicle, or any other dynamic media — that is paid for by the brand. But here's the key: Sponsored content, when done correctly, is a valuable content experience that retains the same voice and integrity of the brand that's sponsoring the placement. This seamless integration into the natural flow of content that the publisher normally creates makes it one of the most effective ways to build site revenue. In fact, 80% of readers believe authentic content is the main factor that will drive them to follow or engage with a brand.

Keep reading... Show less

RebelMouse Q2 2021 Platform Performance Updates

Q2 of 2021 was a big quarter for the open web. Google delayed their release of SEO ranking by CrUX report, and they changed their method for Lighthouse scoring drastically. Our team was a few steps ahead of these changes, and we were able to update our platform so sites in our network had little, if any, performance interruptions.

We invested over 1,592 hours into our platform in Q2 2021 alone, and all of the sites on our platform received the benefits of these updates. To break it down into large buckets, we invested in the following key areas:

  • 538 hours dedicated to new features
  • 725 hours dedicated to improving existing features
  • 329 hours dedicated to performance and infrastructure updates

Here are the major updates that we've added to the RebelMouse platform in Q2.

Keep reading... Show less

How to Use the Pagination Element

You can add pagination to section, tag, and archive pages using RebelMouse's Layout & Design Tool. This can be done through our Pagination element:

Using the Properties card, there are three options that you can configure on the Pagination element:

Keep reading... Show less
Subscribe to Our Newsletter