Subscribe to Our Newsletter

x

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_ur}}
    • 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.

    

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:

    <jinja>
    var date_time={{context.post.post_formatted_created_ts}} ;
    var anythingFromContext ={{context.post.anyhingFromContext}} ;
    </jinja>

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 is not exposed to all users, and it should only be used by advanced users.

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.

How to Include Interactive Elements in Posts

Enhance your articles with rich and creative media

Every article is a fresh chance to grab new readers and nurture loyal followers. This is why we give creators every opportunity to build content rich with media elements that enhance every reader's experience.

Add More Layers to Your Content

You can easily add interactive elements, like charts, to posts on our platform. For example, if you need to embed iframe code into a post, this can be done via our Add Media Bar. To do so, click the code icon (< >):

A text box will appear so you can insert your code:

Embedded Code Across Platforms

One important thing to keep in mind is that Google AMP, AppleNews, and Facebook Instant Articles will not always support embedded code. So if you use an iframe, it's best to turn off distribution to those channels for that particular post. If you have a lot of posts that require embedded code, this could be problematic for growth across those important platforms.

If you do want to use an iframe on a post destined for Google AMP distribution, it can be possible if the iframe is not at the top of the page or within the first 75% of the viewport when the page is scrolled to the top (whichever is smaller). AMP is a fast technology designed for mobile users and iframes are loaded using arbitrary timing that AMP's technology cannot ensure. For this reason, it's suggested that iframes be included in places that are not visible by users upon load.

If you have an article that needs to include an iframe at the top of the page, or within the first 75% of the viewport, AMP can be turned off for that individual article within Entry Editor.

If you don't need an interactive chart to be interactive in nature, can turn it into an image and upload it directly to your post. This way it will work on all platforms, including Google AMP, Apple News, and Facebook Instant Articles. This option, when possible, is ideal to ensure you're optimized for page speed.

Take Advantage of Shortcodes

Another great way to embed media is through our shortcodes functionality. Click here to learn more about shortcodes. Shortcodes can also inserted using the Add Media Bar. Click the brackets icon ([ ]) to choose the shortcode you want to use.

Here's an example of a chart on an article page that's been inserted using a shortcode:

If you have any questions about how to add interactive elements to your content, please email support@rebelmouse.com or talk to your account manager today.

Shortcodes Dashboard: Dynamic Media in Just a Few Clicks

Create multidimensional content with easy-to-find shortcodes

We believe static media is dead, and that every piece of content should be multidimensional and engaging. This is why our platform enables creators so they can add dynamic media to their content in easy and efficient ways.

One simple way to add interactive content to any post is through the use of shortcodes. Shortcodes are small snippets of code that are easier to remember than longer sequences. They typically will activate a feature or embed media into an article.

Keep reading... Show less
Subscribe to Our Newsletter